Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1581590

[PATCH 06/14] perf tests: Synthesize struct instead of using field after variable sized type

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 06/14] perf tests: Synthesize struct instead of using field after variable sized type
Date 2017-02-15 20:10 +0100
Message-ID <tbd7I-3Wc-45@gated-at.bofh.it> (permalink)
References <tbd7H-3Wc-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Arnaldo Carvalho de Melo <acme@redhat.com>

End result is the same, its an ABI, so the struct won't change, avoid
using a GNU extension, so that we can catch other cases that may be bugs.

Caught when building with clang:

  tests/parse-no-sample-id-all.c:53:20: error: field 'attr' with variable sized type 'struct attr_event' not at the end of a struct or class is a GNU extension
        [-Werror,-Wgnu-variable-sized-type-not-at-end]
          struct attr_event attr;
                            ^
  1 error generated.

Testing it:

  # perf test sample_id
  24: Parse with no sample_id_all bit set        : Ok
  #

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-e2vs1x771fc208uvxnwcf08b@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/parse-no-sample-id-all.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c
index 81c6eeaca0f5..65dcf48a92fb 100644
--- a/tools/perf/tests/parse-no-sample-id-all.c
+++ b/tools/perf/tests/parse-no-sample-id-all.c
@@ -50,7 +50,8 @@ static int process_events(union perf_event **events, size_t count)
 }
 
 struct test_attr_event {
-	struct attr_event attr;
+	struct perf_event_header header;
+	struct perf_event_attr	 attr;
 	u64 id;
 };
 
@@ -71,20 +72,16 @@ int test__parse_no_sample_id_all(int subtest __maybe_unused)
 	int err;
 
 	struct test_attr_event event1 = {
-		.attr = {
-			.header = {
-				.type = PERF_RECORD_HEADER_ATTR,
-				.size = sizeof(struct test_attr_event),
-			},
+		.header = {
+			.type = PERF_RECORD_HEADER_ATTR,
+			.size = sizeof(struct test_attr_event),
 		},
 		.id = 1,
 	};
 	struct test_attr_event event2 = {
-		.attr = {
-			.header = {
-				.type = PERF_RECORD_HEADER_ATTR,
-				.size = sizeof(struct test_attr_event),
-			},
+		.header = {
+			.type = PERF_RECORD_HEADER_ATTR,
+			.size = sizeof(struct test_attr_event),
 		},
 		.id = 2,
 	};
-- 
2.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/14] perf/core clang fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-15 20:10 +0100
  [PATCH 08/14] perf tools: Do not put a variable sized type not at the end of a struct Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-15 20:10 +0100
  [PATCH 06/14] perf tests: Synthesize struct instead of using field after variable sized type Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-15 20:10 +0100
  Re: [GIT PULL 00/14] perf/core clang fixes Ingo Molnar <mingo@kernel.org> - 2017-02-16 21:00 +0100

csiph-web