[llvm-commits] [llvm-gcc-4.0] r45801 - /llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp

Chris Lattner sabre at nondot.org
Wed Jan 9 16:48:43 PST 2008


Author: lattner
Date: Wed Jan  9 18:48:43 2008
New Revision: 45801

URL: http://llvm.org/viewvc/llvm-project?rev=45801&view=rev
Log:
Fix a "bug" introduced by attribute(annotate).  Before this patch it 
would always call " ConvertMetadataStringToGV(DECL_SOURCE_FILE(decl));"
even if there are no annotate attributes on a global, causing the string
to be emitted and unused.



Modified:
    llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp

Modified: llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp?rev=45801&r1=45800&r2=45801&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp Wed Jan  9 18:48:43 2008
@@ -714,12 +714,14 @@
   
   // Handle annotate attribute on global.
   tree annotateAttr = lookup_attribute("annotate", DECL_ATTRIBUTES (decl));
+  if (annotateAttr == 0)
+    return;
   
   // Get file and line number
- Constant *lineNo = ConstantInt::get(Type::Int32Ty, DECL_SOURCE_LINE(decl));
- Constant *file = ConvertMetadataStringToGV(DECL_SOURCE_FILE(decl));
- const Type *SBP= PointerType::getUnqual(Type::Int8Ty);
- file = ConstantExpr::getBitCast(file, SBP);
+  Constant *lineNo = ConstantInt::get(Type::Int32Ty, DECL_SOURCE_LINE(decl));
+  Constant *file = ConvertMetadataStringToGV(DECL_SOURCE_FILE(decl));
+  const Type *SBP= PointerType::getUnqual(Type::Int8Ty);
+  file = ConstantExpr::getBitCast(file, SBP);
  
   // There may be multiple annotate attributes. Pass return of lookup_attr 
   //  to successive lookups.
@@ -739,10 +741,12 @@
       assert(TREE_CODE(val) == STRING_CST && 
              "Annotate attribute arg should always be a string");
       Constant *strGV = TreeConstantToLLVM::EmitLV_STRING_CST(val);
-      Constant *Element[4] = {ConstantExpr::getBitCast(GV,SBP),
+      Constant *Element[4] = {
+        ConstantExpr::getBitCast(GV,SBP),
         ConstantExpr::getBitCast(strGV,SBP),
         file,
-        lineNo};
+        lineNo
+      };
  
       AttributeAnnotateGlobals.push_back(ConstantStruct::get(Element, 4, false));
     }





More information about the llvm-commits mailing list