diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-04-30 20:35:01 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-04-30 20:35:01 +0000 |
| commit | 0be628ff646a87fc691622633d94542eb7da078c (patch) | |
| tree | 6e5ea9a7d0d3f3d583012cb37dcd557efc3fe839 | |
| parent | 3ca9a9b59cd21673930ee0a5b40ebf914537d7f8 (diff) | |
| download | bcm5719-llvm-0be628ff646a87fc691622633d94542eb7da078c.tar.gz bcm5719-llvm-0be628ff646a87fc691622633d94542eb7da078c.zip | |
Fix a thinko that caused us not to compute __builtin_offset as a
constant expression in C.
llvm-svn: 102762
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 1 | ||||
| -rw-r--r-- | clang/test/Sema/offsetof.c | 3 |
3 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 82526119e2a..00662a53afe 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1943,7 +1943,6 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { case UnaryOperator::AddrOf: case UnaryOperator::Deref: return ICEDiag(2, E->getLocStart()); - case UnaryOperator::OffsetOf: case UnaryOperator::Extension: case UnaryOperator::LNot: case UnaryOperator::Plus: @@ -1952,7 +1951,11 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { case UnaryOperator::Real: case UnaryOperator::Imag: return CheckICE(Exp->getSubExpr(), Ctx); + case UnaryOperator::OffsetOf: + break; } + + // OffsetOf falls through here. } case Expr::OffsetOfExprClass: { // Note that per C99, offsetof must be an ICE. And AFAIK, using diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 445cf17aadf..5ce268bd9eb 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -4202,6 +4202,7 @@ TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { const Node &ON = E->getComponent(I); Component Comp; + Comp.isBrackets = true; Comp.LocStart = ON.getRange().getBegin(); Comp.LocEnd = ON.getRange().getEnd(); switch (ON.getKind()) { diff --git a/clang/test/Sema/offsetof.c b/clang/test/Sema/offsetof.c index cf88465e535..5026193943f 100644 --- a/clang/test/Sema/offsetof.c +++ b/clang/test/Sema/offsetof.c @@ -62,3 +62,6 @@ struct has_bitfields { }; int test3 = __builtin_offsetof(struct has_bitfields, j); // expected-error{{cannot compute offset of bit-field 'j'}} + +typedef struct Array { int array[1]; } Array; +int test4 = __builtin_offsetof(Array, array); |

