[cfe-commits] r167802 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/bool_test.c

Eli Friedman eli.friedman at gmail.com
Mon Nov 12 18:05:15 PST 2012


Author: efriedma
Date: Mon Nov 12 20:05:15 2012
New Revision: 167802

URL: http://llvm.org/viewvc/llvm-project?rev=167802&view=rev
Log:
Fix IR generation for bool on PPC (and any other target where bool is not 8 bits in memory).

PR11777.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGen/bool_test.c

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=167802&r1=167801&r2=167802&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Nov 12 20:05:15 2012
@@ -935,8 +935,8 @@
   llvm::APInt Min;
   llvm::APInt End;
   if (IsBool) {
-    Min = llvm::APInt(8, 0);
-    End = llvm::APInt(8, 2);
+    Min = llvm::APInt(getContext().getTypeSize(Ty), 0);
+    End = llvm::APInt(getContext().getTypeSize(Ty), 2);
   } else {
     const EnumDecl *ED = ET->getDecl();
     llvm::Type *LTy = ConvertTypeForMem(ED->getIntegerType());
@@ -1031,8 +1031,9 @@
     // This should really always be an i1, but sometimes it's already
     // an i8, and it's awkward to track those cases down.
     if (Value->getType()->isIntegerTy(1))
-      return Builder.CreateZExt(Value, Builder.getInt8Ty(), "frombool");
-    assert(Value->getType()->isIntegerTy(8) && "value rep of bool not i1/i8");
+      return Builder.CreateZExt(Value, ConvertTypeForMem(Ty), "frombool");
+    assert(Value->getType()->isIntegerTy(getContext().getTypeSize(Ty)) &&
+           "wrong value rep of bool");
   }
 
   return Value;
@@ -1041,7 +1042,8 @@
 llvm::Value *CodeGenFunction::EmitFromMemory(llvm::Value *Value, QualType Ty) {
   // Bool has a different representation in memory than in registers.
   if (hasBooleanRepresentation(Ty)) {
-    assert(Value->getType()->isIntegerTy(8) && "memory rep of bool not i8");
+    assert(Value->getType()->isIntegerTy(getContext().getTypeSize(Ty)) &&
+           "wrong value rep of bool");
     return Builder.CreateTrunc(Value, Builder.getInt1Ty(), "tobool");
   }
 

Modified: cfe/trunk/test/CodeGen/bool_test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bool_test.c?rev=167802&r1=167801&r2=167802&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/bool_test.c (original)
+++ cfe/trunk/test/CodeGen/bool_test.c Mon Nov 12 20:05:15 2012
@@ -1,6 +1,18 @@
 // REQUIRES: ppc32-registered-target
-// RUN: %clang_cc1 -triple powerpc-apple-darwin -emit-llvm -o - %s| FileCheck -check-prefix=DARWINPPC-CHECK %s
+// RUN: %clang_cc1 -triple powerpc-apple-macosx10.4.0 -emit-llvm -o - %s -O2 -disable-llvm-optzns | FileCheck %s
 
 int boolsize = sizeof(_Bool);
-//DARWINPPC-CHECK: boolsize = global i32 4, align 4
+// CHECK: boolsize = global i32 4, align 4
 
+void f(_Bool *x, _Bool *y) {
+  *x = *y;
+}
+
+// CHECK: define void @f(
+// CHECK: [[FROMMEM:%.*]] = load i32* %
+// CHECK: [[BOOLVAL:%.*]] = trunc i32 [[FROMMEM]] to i1
+// CHECK: [[TOMEM:%.*]] = zext i1 [[BOOLVAL]] to i32
+// CHECK: store i32 [[TOMEM]]
+// CHECK: ret void
+
+// CHECK: metadata !{i32 0, i32 2}





More information about the cfe-commits mailing list