Author: Erich Keane Date: 2022-06-07T11:30:59-07:00 New Revision: 5c3bde96250c5260773009e691f92cb4823372df
URL: https://github.com/llvm/llvm-project/commit/5c3bde96250c5260773009e691f92cb4823372df DIFF: https://github.com/llvm/llvm-project/commit/5c3bde96250c5260773009e691f92cb4823372df.diff LOG: [CodeGen] Fix an issue when the 'extern C' replacement names broke Originally broken by me in D122608, this is a regression where we attempt to replace an extern-C thing with 'itself'. The problem is that we end up deleting it, causing the value to fail when it gets put into llvm.used. Added: clang/test/CodeGenCXX/externc-used-not-replaced.cpp Modified: clang/lib/CodeGen/CodeGenModule.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c3507fad0d79d..2760450ffcd2f 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6388,6 +6388,10 @@ bool CodeGenModule::CheckAndReplaceExternCIFuncs(llvm::GlobalValue *Elem, // here. llvm::SmallVector<llvm::ConstantExpr *> CEs; + // It isn't valid to replace the extern-C ifuncs if all we find is itself! + if (Elem == CppFunc) + return false; + // First make sure that all users of this are ifuncs (or ifuncs via a // bitcast), and collect the list of ifuncs and CEs so we can work on them // later. @@ -6456,7 +6460,7 @@ void CodeGenModule::EmitStaticExternCAliases() { // If Val is null, that implies there were multiple declarations that each // had a claim to the unmangled name. In this case, generation of the alias - // is suppressed. See CodeGenModule::MaybeHandleStaticInExterC. + // is suppressed. See CodeGenModule::MaybeHandleStaticInExternC. if (!Val) break; diff --git a/clang/test/CodeGenCXX/externc-used-not-replaced.cpp b/clang/test/CodeGenCXX/externc-used-not-replaced.cpp new file mode 100644 index 0000000000000..133b3a66c53f4 --- /dev/null +++ b/clang/test/CodeGenCXX/externc-used-not-replaced.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple x86_64-windows -emit-llvm -o - %s | FileCheck %s + +extern "C" { + const char a __attribute__((used)){}; +} + +// CHECK: @a = internal constant i8 0 +// CHECK: @llvm.used = appending global [1 x ptr] [ptr @a] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits