diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c3507fad0d79d9..2760450ffcd2f1 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 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 00000000000000..133b3a66c53f4c --- /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]