llvm-project/clang/test/Modules/macro-identifier-hiding.c
Volodymyr Sapsai 81739c39db
[Modules] Fix an identifier hiding a function-like macro definition. (#135471)
We emit a macro definition only in a module defining it. But it means
that if another module has an identifier with the same name as the
macro, the users of such module won't be able to use the macro anymore.

Fix by storing that an identifier has a macro definition that's not in a
current module (`MacroDirectivesOffset == 0`). This way
`IdentifierLookupVisitor` knows not to stop at the first module with an
identifier but to keep checking included modules for the actual macro
definition.

Fixes issue #32040.

rdar://30258278
2025-04-16 10:14:05 -07:00

30 lines
972 B
C

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache \
// RUN: -fsyntax-only %t/test.c -verify
// Test again with the populated module cache.
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache \
// RUN: -fsyntax-only %t/test.c -verify
// Test that an identifier with the same name as a macro doesn't hide this
// macro from the includers.
//--- macro-definition.h
#define __P(protos) ()
#define __Q(protos) ()
//--- macro-transitive.h
#include "macro-definition.h"
void test(int __P) {} // not "interesting" identifier
struct __Q {}; // "interesting" identifier
//--- 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(());