[PATCH] D93630: [Attr] Apply GNU-style attributes to expression statements

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 22 07:04:27 PST 2020


aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Thank you for working on this, it's a problem that's annoyed me for a while but I've never found a satisfactory solution to. Unfortunately, it causes us to reject valid code (which is the same problem I kept running up against when I last tried).



================
Comment at: clang/test/Index/blocks.c:8
   static struct foo _foo;
-  __block i = 0;
+  __block int i = 0;
   ^ int_t(struct foo *foo) { return (int_t) foo->x + i; }(&_foo);
----------------
This change should not be necessary as the original code was valid (and I think was testing that validity, but could probably use a comment to make that explicit).


================
Comment at: clang/test/Sema/address_spaces.c:12
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x; // expected-error {{'address_space' attribute cannot be applied to a statement}}
+  // expected-error at -1 {{use of undeclared identifier 'x'}}
----------------
This breaks valid C89 code that uses implicit int (it is also a less helpful diagnostic, but that's secondary to the rejects valid bug).


================
Comment at: clang/test/Sema/block-literal.c:44
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable (missing __block type specifier)}}
-  __block y = 7;    // expected-warning {{type specifier missing, defaults to 'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;           // expected-error {{use of undeclared identifier 'y'}}
+  __block int z = 7;
----------------
This is also valid C89 that should not be rejected.


================
Comment at: clang/test/SemaTemplate/address_space-dependent.cpp:12-13
 
-  __attribute__((address_space(J))) * x; // expected-error {{C++ requires a type specifier for all declarations}}
+  __attribute__((address_space(J))) * x; // expected-error {{use of undeclared identifier 'x'}}
+  // expected-error at -1 {{'address_space' attribute cannot be applied to a statement}}
 
----------------
I think this is a pretty unfortunate degradation of diagnostic wording. The code looks like a somewhat validish declaration, so the diagnostic about a missing type specifier is more helpful than a use of an undeclared identifier that the user is likely trying to declare.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93630/new/

https://reviews.llvm.org/D93630



More information about the cfe-commits mailing list