r229204 - CodeGen: Correctly convert atomic bool from i8 to i1
David Majnemer
david.majnemer at gmail.com
Fri Feb 13 17:35:08 PST 2015
Author: majnemer
Date: Fri Feb 13 19:35:07 2015
New Revision: 229204
URL: http://llvm.org/viewvc/llvm-project?rev=229204&view=rev
Log:
CodeGen: Correctly convert atomic bool from i8 to i1
Bools are a little tricky, they are i8 in memory and must be coerced
back to i1 before further operations can be performed on them.
This fixes PR22577.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/atomic_ops.c
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=229204&r1=229203&r2=229204&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Feb 13 19:35:07 2015
@@ -1140,7 +1140,7 @@ llvm::Value *CodeGenFunction::EmitLoadOf
LValue lvalue = LValue::MakeAddr(Addr, Ty,
CharUnits::fromQuantity(Alignment),
getContext(), TBAAInfo);
- return EmitAtomicLoad(lvalue, Loc).getScalarVal();
+ return EmitFromMemory(EmitAtomicLoad(lvalue, Loc).getScalarVal(), Ty);
}
llvm::LoadInst *Load = Builder.CreateLoad(Addr);
Modified: cfe/trunk/test/CodeGen/atomic_ops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic_ops.c?rev=229204&r1=229203&r2=229204&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/atomic_ops.c (original)
+++ cfe/trunk/test/CodeGen/atomic_ops.c Fri Feb 13 19:35:07 2015
@@ -16,3 +16,13 @@ void foo(int x)
// CHECK: {{(cmpxchg i16*|i1 @__atomic_compare_exchange\(i32 2, )}}
}
+
+extern _Atomic _Bool b;
+
+_Bool bar() {
+// CHECK-LABEL: @bar
+// CHECK: %[[load:.*]] = load atomic i8* @b seq_cst, align 1
+// CHECK: %[[tobool:.*]] = trunc i8 %[[load]] to i1
+// CHECK: ret i1 %[[tobool]]
+ return b;
+}
More information about the cfe-commits
mailing list