]> granicus.if.org Git - clang/commitdiff
Fix isIntegerConstantExpr eval of __builtin_offsetof to return result
authorDaniel Dunbar <daniel@zuster.org>
Thu, 28 Aug 2008 18:42:20 +0000 (18:42 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 28 Aug 2008 18:42:20 +0000 (18:42 +0000)
with correct width.
 - PR2728.

Also, fix PR2727 test case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55493 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/Sema/PR2727.c
test/Sema/PR2728.c [new file with mode: 0644]

index 49c76a89d8639ea9b76c1854c5eac5ec75002c9c..1410f7e05ca2ffce1079b5836d41ba8176562488 100644 (file)
@@ -814,6 +814,7 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
       Result = ~Result;
       break;
     case UnaryOperator::OffsetOf:
+      Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
       Result = Exp->evaluateOffsetOf(Ctx);
     }
     break;
index faf934d947a0b3d36468ff485ddbc72211d18372..1b3096f0b58a010bb11aa4c40d00ddf44351a81e 100644 (file)
@@ -1,3 +1,6 @@
+// RUN: clang -verify -fsyntax-only -std=c90 %s &&
+// RUN: clang -verify -fsyntax-only -std=c99 %s
+
 int f (int x)
 {
   // sizeof applied to a type should not delete the type.
diff --git a/test/Sema/PR2728.c b/test/Sema/PR2728.c
new file mode 100644 (file)
index 0000000..01a3be7
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: clang -verify -fsyntax-only -std=c90 %s &&
+// RUN: clang -verify -fsyntax-only -std=c99 %s
+
+struct s
+{
+  int a;
+};
+
+int a[__builtin_offsetof(struct s, a) == 0];