[PATCH] D51329: [Attribute/Diagnostics] Print macro instead of whole attribute for address_space

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 30 09:33:46 PDT 2018

leonardchan marked 5 inline comments as done.
leonardchan added a comment.

@rsmith When you clarify what you mean by `outermost macro expansion`? Say I have the following:

  #define ATTR __attribute__
  #define AS(i) address_space(i)
  #define AS1 ATTR((address_space(1)))
  #define AS2 ATTR((AS(2)))
  int cmp(AS1 char *x, AS2 char *y) {
    return x < y ? x : y;

`AS1 char *` and `AS2 char *` would be diagnosed for an error relating to mismatched types, but I think `outermost macro expansion` implies either `ATTR` or `AS` would be the identifier stored as opposed to `AS1` and `AS2`.

Would it be simpler to instead just check:

- the starting `__attribute__` token was the start of a macro expansion
- the ending right parenthesis token was the end of a macro expansion
- both start and end tokens had the same location to indicate this attribute was used in a macro

After fulfulling these, we can call `Lexer::getSourceText()` to get the spelling of the macro from this SourceLocation.

  rC Clang


More information about the cfe-commits mailing list