[clang] [clang][Modules] Keep existing global definition on type mismatch in GetOrCreateLLVMGlobal (PR #223877)

Michael Park via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 18 18:08:42 PDT 2026


mpark wrote:

I agree with @yuxuanchen1997 on this one that this is not a AST merging issue. It's an actual codegen bug where the llvm type differs in a subsequent duplicate definition. I was able to get AI to produce a non-modules repro, though it involves OpenMP.
```cpp
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple -fopenmp \
// RUN:   -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s

struct P {
  constexpr P() : x(0) {}
  ~P();

  union {
    int x;
    long y;
  };
};

inline P S;
#pragma omp declare target(S)

inline const int *PTR = &S.x;
int use() { return S.x + *PTR; }

// CHECK: @S = linkonce_odr{{.*}} global { { i32, [4 x i8] } }
// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }]
// CHECK-SAME: ptr @__cxx_global_var_init, ptr @S
// CHECK: define internal void @__cxx_global_var_init()
// CHECK-NOT: define {{.*}} @__cxx_global_var_init
```

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


More information about the cfe-commits mailing list