Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modules] Fix using va_list with modules and a precompiled header. #100837

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

vsapsai
Copy link
Collaborator

@vsapsai vsapsai commented Jul 26, 2024

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.

rdar://130947515

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.

rdar://130947515
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules labels Jul 26, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 26, 2024

@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Volodymyr Sapsai (vsapsai)

Changes

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.

rdar://130947515


Full diff: https://github.com/llvm/llvm-project/pull/100837.diff

2 Files Affected:

  • (modified) clang/lib/Sema/Sema.cpp (+7)
  • (added) clang/test/Modules/builtin-vararg.c (+83)
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 2e989f0ba6fe4..19d8692ee6484 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);
 
diff --git a/clang/test/Modules/builtin-vararg.c b/clang/test/Modules/builtin-vararg.c
new file mode 100644
index 0000000000000..ed6e6aeb6e50f
--- /dev/null
+++ b/clang/test/Modules/builtin-vararg.c
@@ -0,0 +1,83 @@
+// Check how builtins using varargs behave with the modules.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -triple x86_64-apple-darwin \
+// RUN:   -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules \
+// RUN:   -emit-module -fmodule-name=DeclareVarargs \
+// RUN:   -x c %t/include/module.modulemap -o %t/DeclareVarargs.pcm \
+// RUN:   -fmodule-map-file=%t/resource_dir/module.modulemap -isystem %t/resource_dir
+// RUN: %clang_cc1 -triple x86_64-apple-darwin \
+// RUN:   -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules \
+// RUN:   -emit-pch -fmodule-name=Prefix \
+// RUN:   -x c-header %t/prefix.pch -o %t/prefix.pch.gch \
+// RUN:   -fmodule-map-file=%t/include/module.modulemap -fmodule-file=DeclareVarargs=%t/DeclareVarargs.pcm \
+// RUN:   -I %t/include
+// RUN: %clang_cc1 -triple x86_64-apple-darwin \
+// RUN:   -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules \
+// RUN:   -emit-obj -fmodule-name=test \
+// RUN:   -x c %t/test.c -o %t/test.o \
+// RUN:   -Werror=incompatible-pointer-types \
+// RUN:   -fmodule-file=%t/DeclareVarargs.pcm -include-pch %t/prefix.pch.gch \
+// RUN:   -I %t/include
+
+//--- include/declare-varargs.h
+#ifndef DECLARE_VARARGS_H
+#define DECLARE_VARARGS_H
+
+#include <stdarg.h>
+
+int vprintf(const char *format, va_list args);
+
+// 1. initializeBuiltins 'acos' causes its deserialization and deserialization
+//    of 'implementation_of_builtin'. Because this is done before Sema initialization,
+//    'implementation_of_builtin' DeclID is added to PreloadedDeclIDs.
+#undef acos
+#define acos(__x) implementation_of_builtin(__x)
+
+// 2. Because of 'static' the function isn't added to EagerlyDeserializedDecls
+//    and not deserialized in `ASTReader::StartTranslationUnit` before `ASTReader::InitializeSema`.
+// 3. Because of '__overloadable__' attribute the function requires name mangling during deserialization.
+//    And the name mangling requires '__builtin_va_list' decl.
+//    Because the function is added to PreloadedDeclIDs, the deserialization happens in `ASTReader::InitializeSema`.
+static int __attribute__((__overloadable__)) implementation_of_builtin(int x) {
+  return x;
+}
+
+#endif // DECLARE_VARARGS_H
+
+//--- include/module.modulemap
+module DeclareVarargs {
+  header "declare-varargs.h"
+  export *
+}
+
+//--- resource_dir/stdarg.h
+#ifndef STDARG_H
+#define STDARG_H
+
+typedef __builtin_va_list va_list;
+#define va_start(ap, param) __builtin_va_start(ap, param)
+#define va_end(ap) __builtin_va_end(ap)
+
+#endif // STDARG_H
+
+//--- resource_dir/module.modulemap
+module _Builtin_stdarg {
+  header "stdarg.h"
+  export *
+}
+
+//--- prefix.pch
+#include <declare-varargs.h>
+
+//--- test.c
+#include <declare-varargs.h>
+
+void test(const char *format, ...) {
+  va_list argParams;
+  va_start(argParams, format);
+  vprintf(format, argParams);
+  va_end(argParams);
+}

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@vsapsai
Copy link
Collaborator Author

vsapsai commented Aug 2, 2024

LGTM.

Thanks for the review!

@vsapsai vsapsai merged commit d02757c into llvm:main Aug 2, 2024
11 checks passed
@vsapsai vsapsai deleted the builtin-varargs-in-modules branch August 2, 2024 15:32
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 2, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/3117

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Modules/builtin-vararg.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
+ rm -rf /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
RUN: at line 4: split-file /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Modules/builtin-vararg.c /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
+ split-file /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Modules/builtin-vararg.c /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
RUN: at line 6: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-module -fmodule-name=DeclareVarargs    -x c /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -o /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm    -fmodule-map-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir/module.modulemap -isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-module -fmodule-name=DeclareVarargs -x c /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -o /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -fmodule-map-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir/module.modulemap -isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir
RUN: at line 11: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-pch -fmodule-name=Prefix    -x c-header /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch -o /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch    -fmodule-map-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -fmodule-file=DeclareVarargs=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm    -I /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-pch -fmodule-name=Prefix -x c-header /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch -o /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch -fmodule-map-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -fmodule-file=DeclareVarargs=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -I /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
RUN: at line 17: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-obj -fmodule-name=test    -x c /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.c -o /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.o    -Werror=incompatible-pointer-types    -fmodule-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -include-pch /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch    -I /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-obj -fmodule-name=test -x c /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.c -o /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.o -Werror=incompatible-pointer-types -fmodule-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -include-pch /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch -I /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
error: unable to create target: 'No available targets are compatible with triple "x86_64-apple-darwin"'
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 2, 2024

LLVM Buildbot has detected a new failure on builder clang-aarch64-quick running on linaro-clang-aarch64-quick while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/2302

Here is the relevant piece of the build log for the reference:

Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: Modules/builtin-vararg.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
+ rm -rf /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
RUN: at line 4: split-file /home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/clang/test/Modules/builtin-vararg.c /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
+ split-file /home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/clang/test/Modules/builtin-vararg.c /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
RUN: at line 6: /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-module -fmodule-name=DeclareVarargs    -x c /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -o /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm    -fmodule-map-file=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir/module.modulemap -isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir
+ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-module -fmodule-name=DeclareVarargs -x c /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -o /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -fmodule-map-file=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir/module.modulemap -isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir
RUN: at line 11: /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-pch -fmodule-name=Prefix    -x c-header /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch -o /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch    -fmodule-map-file=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -fmodule-file=DeclareVarargs=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm    -I /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
+ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-pch -fmodule-name=Prefix -x c-header /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch -o /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch -fmodule-map-file=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -fmodule-file=DeclareVarargs=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -I /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
RUN: at line 17: /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-obj -fmodule-name=test    -x c /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.c -o /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.o    -Werror=incompatible-pointer-types    -fmodule-file=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -include-pch /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch    -I /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
+ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-obj -fmodule-name=test -x c /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.c -o /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.o -Werror=incompatible-pointer-types -fmodule-file=/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -include-pch /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch -I /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
error: unable to create target: 'No available targets are compatible with triple "x86_64-apple-darwin"'
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 2, 2024

LLVM Buildbot has detected a new failure on builder clang-armv8-quick running on linaro-clang-armv8-quick while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/2288

Here is the relevant piece of the build log for the reference:

Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: Modules/builtin-vararg.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
+ rm -rf /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
RUN: at line 4: split-file /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Modules/builtin-vararg.c /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
+ split-file /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Modules/builtin-vararg.c /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp
RUN: at line 6: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-module -fmodule-name=DeclareVarargs    -x c /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -o /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm    -fmodule-map-file=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir/module.modulemap -isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-module -fmodule-name=DeclareVarargs -x c /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -o /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -fmodule-map-file=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir/module.modulemap -isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/resource_dir
RUN: at line 11: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-pch -fmodule-name=Prefix    -x c-header /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch -o /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch    -fmodule-map-file=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -fmodule-file=DeclareVarargs=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm    -I /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-pch -fmodule-name=Prefix -x c-header /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch -o /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch -fmodule-map-file=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include/module.modulemap -fmodule-file=DeclareVarargs=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -I /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
RUN: at line 17: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin    -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules    -emit-obj -fmodule-name=test    -x c /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.c -o /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.o    -Werror=incompatible-pointer-types    -fmodule-file=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -include-pch /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch    -I /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -triple x86_64-apple-darwin -fmodules -fno-implicit-modules -fbuiltin-headers-in-system-modules -emit-obj -fmodule-name=test -x c /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.c -o /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/test.o -Werror=incompatible-pointer-types -fmodule-file=/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/DeclareVarargs.pcm -include-pch /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/prefix.pch.gch -I /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/test/Modules/Output/builtin-vararg.c.tmp/include
error: unable to create target: 'No available targets are compatible with triple "x86_64-apple-darwin"'
1 error generated.

--

********************


@vsapsai
Copy link
Collaborator Author

vsapsai commented Aug 2, 2024

Looks like need something like // REQUIRES: x86-registered-target in the test. But still need to check the correct approach in other tests.

vsapsai added a commit that referenced this pull request Aug 2, 2024
…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
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
…lvm#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.

rdar://130947515
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
…header. (llvm#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
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
…header. (llvm#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants