robertlytton added you to the CC list for the revision "XCore target: fix bug 
in dereferencing null pointer.".

Hi friedgold,

The code only affects XCore targets.
The 'const VarDecl *D' was not being checked for null prior to dereferencing.
This was discovered whilst compiling a empty destructor.

Also add testing of cpp ABI output where it differs from C ABI output.

http://reviews.llvm.org/D3450

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/xcore-abi.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1631,17 +1631,18 @@
         D->isStaticDataMember() && D->hasInit() &&
         !D->isThisDeclarationADefinition())
       EmitGlobalVarDefinition(D);
+
+    // Handle XCore specific ABI requirements.
+    if (getTarget().getTriple().getArch() == llvm::Triple::xcore &&
+        D->getLanguageLinkage() == CLanguageLinkage &&
+        D->getType().isConstant(Context) &&
+        isExternallyVisible(LV.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;
Index: test/CodeGen/xcore-abi.cpp
===================================================================
--- /dev/null
+++ test/CodeGen/xcore-abi.cpp
@@ -0,0 +1,25 @@
+// 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;
+
+// Make sure null 'VarDecl*' are not indirected.
+class C {
+public:
+  ~C(){};
+};
+C c;
+
+// CHECK: "no-frame-pointer-elim"="false"
+// CHECK-NOT: "no-frame-pointer-elim-non-leaf"
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1631,17 +1631,18 @@
         D->isStaticDataMember() && D->hasInit() &&
         !D->isThisDeclarationADefinition())
       EmitGlobalVarDefinition(D);
+
+    // Handle XCore specific ABI requirements.
+    if (getTarget().getTriple().getArch() == llvm::Triple::xcore &&
+        D->getLanguageLinkage() == CLanguageLinkage &&
+        D->getType().isConstant(Context) &&
+        isExternallyVisible(LV.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;
Index: test/CodeGen/xcore-abi.cpp
===================================================================
--- /dev/null
+++ test/CodeGen/xcore-abi.cpp
@@ -0,0 +1,25 @@
+// 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;
+
+// Make sure null 'VarDecl*' are not indirected.
+class C {
+public:
+  ~C(){};
+};
+C c;
+
+// CHECK: "no-frame-pointer-elim"="false"
+// CHECK-NOT: "no-frame-pointer-elim-non-leaf"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to