[clang] cafe50d - Explicitly initialize opaque pointer mode in CodeGenAction

Matthias Braun via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 7 12:49:11 PST 2022


Author: Matthias Braun
Date: 2022-11-07T12:31:28-08:00
New Revision: cafe50daf525971ffc3b8c5f2f6343d24e381384

URL: https://github.com/llvm/llvm-project/commit/cafe50daf525971ffc3b8c5f2f6343d24e381384
DIFF: https://github.com/llvm/llvm-project/commit/cafe50daf525971ffc3b8c5f2f6343d24e381384.diff

LOG: Explicitly initialize opaque pointer mode in CodeGenAction

Explicitly call `LLVMContext::setOpaquePointers` in `CodeGenAction`
before loading any IR files. With this we use the mode specified on the
command-line rather than lazily initializing it based on the contents of
the IR.

This helps when using `-fthinlto-index` which may end up mixing files
with typed and opaque pointer types which fails when the first file
happened to use typed pointers since we cannot downgrade IR with opaque
pointer types to typed pointer types.

Differential Revision: https://reviews.llvm.org/D137475

Added: 
    clang/test/CodeGen/Inputs/thinlto-opaque.ll
    clang/test/CodeGen/thinlto-opaque-typed-mix.ll

Modified: 
    clang/lib/CodeGen/CodeGenAction.cpp
    clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 52d0417a4fa6b..b723a52fbdd59 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1102,6 +1102,8 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
   CompilerInstance &CI = getCompilerInstance();
   SourceManager &SM = CI.getSourceManager();
 
+  VMContext->setOpaquePointers(CI.getCodeGenOpts().OpaquePointers);
+
   // For ThinLTO backend invocations, ensure that the context
   // merges types based on ODR identifiers. We also need to read
   // the correct module out of a multi-module bitcode file.

diff  --git a/clang/test/CodeGen/Inputs/thinlto-opaque.ll b/clang/test/CodeGen/Inputs/thinlto-opaque.ll
new file mode 100644
index 0000000000000..bd576ab830143
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/thinlto-opaque.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64--"
+
+define ptr @f2() {
+  ret ptr null
+}

diff  --git a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll b/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
index 959d89d61ab27..2309ed717c2a2 100644
--- a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
+++ b/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
@@ -100,7 +100,7 @@ cont2:
   ; CHECK-IR: br i1 {{.*}}, label %trap
 
   ; We still have to call it as virtual.
-  ; CHECK-IR: %call3 = tail call i32 %7
+  ; CHECK-IR: %call3 = tail call i32 {{%[0-9]+}}
   %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
   ret i32 %call3
 }

diff  --git a/clang/test/CodeGen/thinlto-opaque-typed-mix.ll b/clang/test/CodeGen/thinlto-opaque-typed-mix.ll
new file mode 100644
index 0000000000000..1cd301f290e9b
--- /dev/null
+++ b/clang/test/CodeGen/thinlto-opaque-typed-mix.ll
@@ -0,0 +1,23 @@
+; REQUIRES: x86-registered-target
+; Test that mixing bitcode file with opaque and typed pointers works.
+
+; RUN: mkdir -p %t
+; RUN: opt -module-summary -o %t/typed.bc %s
+; RUN: opt -module-summary -o %t/opaque.bc %S/Inputs/thinlto-opaque.ll
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t/typed.bc %t/opaque.bc \
+; RUN:   -o %t/native.o -r %t/typed.bc,main,plx -r %t/typed.bc,f2, \
+; RUN:   -r %t/opaque.bc,f2,p
+
+; RUN: %clang_cc1 -triple x86_64-- -emit-obj -o %t/native.o %t/typed.bc \
+; RUN:   -Wno-override-module \
+; RUN:   -fthinlto-index=%t/typed.bc.thinlto.bc
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64--"
+
+declare i8* @f2()
+
+define i32 @main() {
+  call i8* @f2()
+  ret i32 0
+}


        


More information about the cfe-commits mailing list