[clang] [Modules] Fix an identifier hiding a function-like macro definition. (PR #135471)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 14 10:58:37 PDT 2025


================
@@ -3871,7 +3874,8 @@ class ASTIdentifierTableTrait {
     if (isInterestingIdentifier(II, MacroOffset)) {
       DataLen += 2; // 2 bytes for builtin ID
       DataLen += 2; // 2 bytes for flags
-      if (MacroOffset)
+      if (MacroOffset || (II->hasMacroDefinition() &&
+                          II->hasFETokenInfoChangedSinceDeserialization()))
----------------
jansvoboda11 wrote:

The way this condition works makes me think of this situation:

```
//--- macro-definition.h
#define __P(protos) ()
#define __Q(protos) ()

//--- macro-transitive.h
void test(int __P) {} // not "interesting" identifier
struct __Q {};        // "interesting" identifier
#include "macro-definition.h" // NOTE: Import of the macros module
                              // comes after local declarations.

//--- module.modulemap
module MacroDefinition { header "macro-definition.h" export * }
module MacroTransitive { header "macro-transitive.h" export * }

//--- test.c
// expected-no-diagnostics
#include "macro-transitive.h"
void foo __P(());
void bar __Q(());
```

When writing the PCM for the MacroTransitive module, I'd expect `II->hasFETokenInfoChangedSinceDeserialization()` to be false and `ASTWriter` therefore skipping serializing the  fact that `__P` and `__Q` have macros attached to them. How is this working out in this case? This modified test passes, just curious why.

https://github.com/llvm/llvm-project/pull/135471


More information about the cfe-commits mailing list