diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-11-15 22:45:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-11-15 22:45:29 +0000 |
commit | a3e01cf822f7415337e5424af3c6f4c94a12c1b9 (patch) | |
tree | 33e9d9c041d05e24fa06fda646b16a327e3bb159 /clang/test | |
parent | 9c13dd027bf2c3ff8d81d60af3e893a01515f1ff (diff) | |
download | bcm5719-llvm-a3e01cf822f7415337e5424af3c6f4c94a12c1b9.tar.gz bcm5719-llvm-a3e01cf822f7415337e5424af3c6f4c94a12c1b9.zip |
PR8455: Handle an attribute between a goto label and a variable declaration per
the GNU documentation: the attribute only appertains to the label if it is
followed by a semicolon. Based on a patch by Aaron Ballman!
llvm-svn: 194869
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Misc/ast-dump-attr.cpp | 16 | ||||
-rw-r--r-- | clang/test/Sema/warn-unused-label.c | 4 | ||||
-rw-r--r-- | clang/test/SemaCXX/warn-unused-variables.cpp | 25 |
3 files changed, 44 insertions, 1 deletions
diff --git a/clang/test/Misc/ast-dump-attr.cpp b/clang/test/Misc/ast-dump-attr.cpp index 3efcd098b37..729be1f2477 100644 --- a/clang/test/Misc/ast-dump-attr.cpp +++ b/clang/test/Misc/ast-dump-attr.cpp @@ -95,3 +95,19 @@ void *TestVariadicUnsigned1(int) __attribute__((alloc_size(1))); void *TestVariadicUnsigned2(int, int) __attribute__((alloc_size(1,2))); // CHECK: FunctionDecl{{.*}}TestVariadicUnsigned2 // CHECK: AllocSizeAttr{{.*}} 0 1 + +void TestLabel() { +L: __attribute__((unused)) int i; +// CHECK: LabelStmt{{.*}}'L' +// CHECK: VarDecl{{.*}}i 'int' +// CHECK-NEXT: UnusedAttr{{.*}} + +M: __attribute(()) int j; +// CHECK: LabelStmt {{.*}} 'M' +// CHECK-NEXT: DeclStmt +// CHECK-NEXT: VarDecl {{.*}} j 'int' + +N: __attribute(()) ; +// CHECK: LabelStmt {{.*}} 'N' +// CHECK-NEXT: NullStmt +} diff --git a/clang/test/Sema/warn-unused-label.c b/clang/test/Sema/warn-unused-label.c index 48370a5fd64..4b1dbbf2469 100644 --- a/clang/test/Sema/warn-unused-label.c +++ b/clang/test/Sema/warn-unused-label.c @@ -9,3 +9,7 @@ void f() { goto d; return; } + +void PR8455() { + L: __attribute__((unused)) return; // ok, no semicolon required +} diff --git a/clang/test/SemaCXX/warn-unused-variables.cpp b/clang/test/SemaCXX/warn-unused-variables.cpp index 00597f929b2..93d2f6f9563 100644 --- a/clang/test/SemaCXX/warn-unused-variables.cpp +++ b/clang/test/SemaCXX/warn-unused-variables.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -verify %s template<typename T> void f() { T t; t = 17; @@ -128,3 +128,26 @@ namespace ctor_with_cleanups { } #include "Inputs/warn-unused-variables.h" + +namespace PR8455 { + void f() { + A: // expected-warning {{unused label 'A'}} + __attribute__((unused)) int i; // attribute applies to variable + B: // attribute applies to label + __attribute__((unused)); int j; // expected-warning {{unused variable 'j'}} + } + + void g() { + C: // unused label 'C' will not appear here because an error occurs + __attribute__((unused)) + #pragma weak unused_local_static // expected-error {{expected ';' after __attribute__}} + ; + } + + void h() { + D: // expected-warning {{unused label 'D'}} + #pragma weak unused_local_static + __attribute__((unused)) // expected-warning {{declaration does not declare anything}} + ; + } +} |