r207834 - XCore target: fix bug in dereferencing null pointer.

Robert Lytton robert at xmos.com
Fri May 2 02:33:30 PDT 2014


Author: rlytton
Date: Fri May  2 04:33:30 2014
New Revision: 207834

URL: http://llvm.org/viewvc/llvm-project?rev=207834&view=rev
Log:
XCore target: fix bug in dereferencing null pointer.

Also add basic cpp ABI tests where they differ from C ABI output.

Added:
    cfe/trunk/test/CodeGen/xcore-abi.cpp
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=207834&r1=207833&r2=207834&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri May  2 04:33:30 2014
@@ -1607,17 +1607,18 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
     if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() &&
         isVarDeclInlineInitializedStaticDataMember(D))
       EmitGlobalVarDefinition(D);
+
+    // Handle XCore specific ABI requirements.
+    if (getTarget().getTriple().getArch() == llvm::Triple::xcore &&
+        D->getLanguageLinkage() == CLanguageLinkage &&
+        D->getType().isConstant(Context) &&
+        isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
+      GV->setSection(".cp.rodata");
   }
 
   if (AddrSpace != Ty->getAddressSpace())
     return llvm::ConstantExpr::getAddrSpaceCast(GV, Ty);
 
-  if (getTarget().getTriple().getArch() == llvm::Triple::xcore &&
-      D->getLanguageLinkage() == CLanguageLinkage &&
-      D->getType().isConstant(Context) &&
-      isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
-    GV->setSection(".cp.rodata");
-
   getTargetCodeGenInfo().emitTargetMD(D, GV, *this);
 
   return GV;

Added: cfe/trunk/test/CodeGen/xcore-abi.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xcore-abi.cpp?rev=207834&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/xcore-abi.cpp (added)
+++ cfe/trunk/test/CodeGen/xcore-abi.cpp Fri May  2 04:33:30 2014
@@ -0,0 +1,27 @@
+// REQUIRES: xcore-registered-target
+
+// RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - -x c++ %s | FileCheck %s
+
+// CHECK: target triple = "xcore-unknown-unknown"
+
+
+// C++ constants are not placed into the ".cp.rodata" section.
+// CHECK: @cgx = external constant i32
+extern const int cgx;
+int fcgx() { return cgx;}
+// CHECK: @g1 = global i32 0, align 4
+int g1;
+// CHECK: @cg1 = constant i32 0, align 4
+extern const int cg1 = 0;
+
+// Regression test for a bug in lib/CodeGen/CodeGenModule.cpp which called
+// getLanguageLinkage() via a null 'VarDecl*'. This was an XCore specific
+// conditional call to GV->setSection(".cp.rodata").
+class C {
+public:
+  ~C(){};
+};
+C c;
+
+// CHECK: "no-frame-pointer-elim"="false"
+// CHECK-NOT: "no-frame-pointer-elim-non-leaf"





More information about the cfe-commits mailing list