[cfe-commits] r51838 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/bool-init.c

Eli Friedman eli.friedman at gmail.com
Sun Jun 1 08:31:44 PDT 2008


Author: efriedma
Date: Sun Jun  1 10:31:44 2008
New Revision: 51838

URL: http://llvm.org/viewvc/llvm-project?rev=51838&view=rev
Log:
Make sure _Bool globals have the correct type.


Added:
    cfe/trunk/test/CodeGen/bool-init.c
Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=51838&r1=51837&r2=51838&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sun Jun  1 10:31:44 2008
@@ -793,13 +793,18 @@
                                                 CodeGenFunction *CGF)
 {
   QualType type = E->getType().getCanonicalType();
-  
+
   if (type->isIntegerType()) {
     llvm::APSInt Value(static_cast<uint32_t>(Context.getTypeSize(type)));
     if (E->isIntegerConstantExpr(Value, Context)) {
       return llvm::ConstantInt::get(Value);
     } 
   }
-  
-  return ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E));
+
+  llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E));
+  if (C->getType() == llvm::Type::Int1Ty) {
+    const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
+    C = llvm::ConstantExpr::getZExt(C, BoolTy);
+  }
+  return C;
 }

Added: cfe/trunk/test/CodeGen/bool-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bool-init.c?rev=51838&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/bool-init.c (added)
+++ cfe/trunk/test/CodeGen/bool-init.c Sun Jun  1 10:31:44 2008
@@ -0,0 +1,4 @@
+// RUN: clang -emit-llvm < %s | grep i1 | count 1
+
+// Check that the type of this global isn't i1
+_Bool test = &test;





More information about the cfe-commits mailing list