]> granicus.if.org Git - clang/commitdiff
Make sure _Bool globals have the correct type.
authorEli Friedman <eli.friedman@gmail.com>
Sun, 1 Jun 2008 15:31:44 +0000 (15:31 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 1 Jun 2008 15:31:44 +0000 (15:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51838 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGen/bool-init.c [new file with mode: 0644]

index 4cb3c7bb2a0c1ba6a081809c9cb2368cfe4ced12..be9eaad9acf9ef4a04c2df6ce5334b8f23aef35f 100644 (file)
@@ -793,13 +793,18 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
                                                 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;
 }
diff --git a/test/CodeGen/bool-init.c b/test/CodeGen/bool-init.c
new file mode 100644 (file)
index 0000000..2e5d56a
--- /dev/null
@@ -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;