diff options
author | Volodymyr Sapsai <vsapsai@apple.com> | 2024-08-02 15:15:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-02 19:15:47 -0300 |
commit | d9f786fd13fe03256ef0f2983ecd379d0e7e8c93 (patch) | |
tree | 01d3369be8dd488cd0a2d768db939e0814c8c932 /clang/lib/Sema/Sema.cpp | |
parent | 8cf85653b6f5c90b83f8a5741baad5725d6c6932 (diff) | |
download | llvm-d9f786fd13fe03256ef0f2983ecd379d0e7e8c93.zip llvm-d9f786fd13fe03256ef0f2983ecd379d0e7e8c93.tar.gz llvm-d9f786fd13fe03256ef0f2983ecd379d0e7e8c93.tar.bz2 |
Reland "[Modules] Fix using `va_list` with modules and a precompiled header. (#100837)"
Fix the false warning
> incompatible pointer types passing 'va_list' (aka '__builtin_va_list')
to parameter of type 'struct __va_list_tag *'
[-Wincompatible-pointer-types]
The warning is wrong because both in the function declaration and at the
call site we are using `va_list`.
When we call `ASTContext::getBuiltinVaListDecl` at a specific moment, we
end up re-entering this function which causes creating 2 instances of
`BuiltinVaListDecl` and 2 instances of `VaListTagDecl` but the stored
instances are unrelated to each other because of the call sequence like
getBuiltinVaListDecl
CreateX86_64ABIBuiltinVaListDecl
VaListTagDecl = TagA
indirectly call getBuiltinVaListDecl
CreateX86_64ABIBuiltinVaListDecl
VaListTagDecl = TagB
BuiltinVaListDecl = ListB
BuiltinVaListDecl = ListA
Now we have `BuiltinVaListDecl == ListA` and `VaListTagDecl == TagB`.
For x86_64 '__builtin_va_list' and 'struct __va_list_tag *' are
compatible because '__builtin_va_list' == '__va_list_tag[1]'. But
because we have unrelated decls for VaListDecl and VaListTagDecl the
types are considered incompatible as we are comparing type pointers.
Fix the error by creating `BuiltinVaListDecl` before
`ASTReader::InitializeSema`, so that during
`ASTContext::getBuiltinVaListDecl` ASTReader doesn't try to de-serialize
'__builtin_va_list' and to call `ASTContext::getBuiltinVaListDecl`
again.
Reland with the requirement to have x86 target to avoid errors like
> error: unable to create target: 'No available targets are compatible
with triple "x86_64-apple-darwin"'
rdar://130947515
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 2e989f0b..19d8692 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -310,6 +310,13 @@ void Sema::addImplicitTypedef(StringRef Name, QualType T) { } void Sema::Initialize() { + // Create BuiltinVaListDecl *before* ExternalSemaSource::InitializeSema(this) + // because during initialization ASTReader can emit globals that require + // name mangling. And the name mangling uses BuiltinVaListDecl. + if (Context.getTargetInfo().hasBuiltinMSVaList()) + (void)Context.getBuiltinMSVaListDecl(); + (void)Context.getBuiltinVaListDecl(); + if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) SC->InitializeSema(*this); |