From af3698066a1ea2e5ab4cc08ae9a59620cf18adb7 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 29 Mar 2014 14:19:55 +0000 Subject: CodeGen: Don't crash when replacing functions The peculiarities of C99 create scenario where an LLVM IR function declaration may need to be replaced with a definition baring a different type because the prototype and definition are not required to agree. However, we were not properly deferring this when it occurred. This fixes PR19280. llvm-svn: 205099 --- clang/lib/CodeGen/CodeGenModule.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index addf8d09e41..92f49379f1b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1177,12 +1177,14 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { if (!FD->doesDeclarationForceExternallyVisibleDefinition()) return; - const FunctionDecl *InlineDefinition = 0; - FD->getBody(InlineDefinition); - StringRef MangledName = getMangledName(GD); - DeferredDecls.erase(MangledName); - EmitGlobalDefinition(InlineDefinition); + + // Compute the function info and LLVM type. + const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD); + llvm::Type *Ty = getTypes().GetFunctionType(FI); + + GetOrCreateLLVMFunction(MangledName, Ty, GD, /*ForVTable=*/false, + /*DontDefer=*/false); return; } } else { -- cgit v1.2.3