From a0f596c1fc01d826687e4388b7fccd99cff8dc38 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 9 Aug 2011 18:31:50 +0000 Subject: [PATCH] Print out the variable declaration only if it is a declaration. Otherwise, a 'static' variable will be emitted twice. PR10081 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137134 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 2 +- test/CodeGen/CBackend/pr10081.ll | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/CBackend/pr10081.ll diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 5b9a0a297fb..e4ecb9e1c56 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1817,7 +1817,7 @@ bool CWriter::doInitialization(Module &M) { Out << "\n\n/* Global Variable Declarations */\n"; for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) - if (!I->isDeclaration()) { + if (I->isDeclaration()) { // Ignore special globals, such as debug info. if (getGlobalVariableClass(I)) continue; diff --git a/test/CodeGen/CBackend/pr10081.ll b/test/CodeGen/CBackend/pr10081.ll new file mode 100644 index 00000000000..723bf5c757c --- /dev/null +++ b/test/CodeGen/CBackend/pr10081.ll @@ -0,0 +1,11 @@ +; RUN: llc < %s -march=c | grep {static float _ZL3foo} | count 1 +; PR10081 + +@_ZL3foo = internal global float 0.000000e+00, align 4 + +define float @_Z3barv() nounwind ssp { + %1 = load float* @_ZL3foo, align 4 + %2 = fadd float %1, 1.000000e+00 + store float %2, float* @_ZL3foo, align 4 + ret float %1 +} -- 2.34.1