[cfe-commits] r77829 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/union-init2.c
Eli Friedman
eli.friedman at gmail.com
Sat Aug 1 16:11:24 PDT 2009
Author: efriedma
Date: Sat Aug 1 18:11:24 2009
New Revision: 77829
URL: http://llvm.org/viewvc/llvm-project?rev=77829&view=rev
Log:
Fix a minor issue with unions in the new struct building code.
Added:
cfe/trunk/test/CodeGen/union-init2.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=77829&r1=77828&r2=77829&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Aug 1 18:11:24 2009
@@ -270,7 +270,7 @@
AppendPadding(NumPadBytes);
}
- bool Build(const InitListExpr *ILE) {
+ bool Build(InitListExpr *ILE) {
RecordDecl *RD = ILE->getType()->getAs<RecordType>()->getDecl();
const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
@@ -280,6 +280,9 @@
FieldEnd = RD->field_end();
ElementNo < ILE->getNumInits() && Field != FieldEnd;
++Field, ++FieldNo) {
+ if (RD->isUnion() && ILE->getInitializedFieldInUnion() != *Field)
+ continue;
+
if (Field->isBitField()) {
if (!Field->getIdentifier())
continue;
@@ -330,7 +333,7 @@
public:
static llvm::Constant *BuildStruct(CodeGenModule &CGM, CodeGenFunction *CGF,
- const InitListExpr *ILE) {
+ InitListExpr *ILE) {
ConstStructBuilder Builder(CGM, CGF);
if (!Builder.Build(ILE))
Added: cfe/trunk/test/CodeGen/union-init2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/union-init2.c?rev=77829&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/union-init2.c (added)
+++ cfe/trunk/test/CodeGen/union-init2.c Sat Aug 1 18:11:24 2009
@@ -0,0 +1,4 @@
+// RUN: clang-cc -emit-llvm %s -o - | not grep ptrtoint
+
+// Make sure we generate something sane instead of a ptrtoint
+union x {long long b;union x* a;} r = {.a = &r};
More information about the cfe-commits
mailing list