[cfe-commits] r55607 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/array-init.c

Nuno Lopes nunoplopes at sapo.pt
Mon Sep 1 07:47:09 PDT 2008


Author: nlopes
Date: Mon Sep  1 09:47:06 2008
New Revision: 55607

URL: http://llvm.org/viewvc/llvm-project?rev=55607&view=rev
Log:
make CheckArithmeticConstantExpression() aware of &foo and pointers

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/array-init.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=55607&r1=55606&r2=55607&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep  1 09:47:06 2008
@@ -1076,6 +1076,13 @@
     const Decl *D = cast<DeclRefExpr>(Init)->getDecl();
     if (isa<EnumConstantDecl>(D))
       return false;
+
+    if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
+      QualType Ty = VD->getType();
+      if (Ty->isPointerLikeType() || Ty->isArrayType())
+        return false;
+    }
+
     Diag(Init->getExprLoc(),
          diag::err_init_element_not_constant, Init->getSourceRange());
     return true;
@@ -1098,6 +1105,8 @@
       Diag(Init->getExprLoc(),
            diag::err_init_element_not_constant, Init->getSourceRange());
       return true;
+    case UnaryOperator::AddrOf:
+      return false;
     case UnaryOperator::SizeOf:
     case UnaryOperator::AlignOf:
     case UnaryOperator::OffsetOf:
@@ -1160,12 +1169,7 @@
   case Expr::ImplicitCastExprClass:
   case Expr::ExplicitCastExprClass: {
     const Expr *SubExpr = cast<CastExpr>(Init)->getSubExpr();
-    if (SubExpr->getType()->isArithmeticType())
-      return CheckArithmeticConstantExpression(SubExpr);
-
-    Diag(Init->getExprLoc(),
-         diag::err_init_element_not_constant, Init->getSourceRange());
-    return true;
+    return CheckArithmeticConstantExpression(SubExpr);
   }
   case Expr::ConditionalOperatorClass: {
     const ConditionalOperator *Exp = cast<ConditionalOperator>(Init);

Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=55607&r1=55606&r2=55607&view=diff

==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Mon Sep  1 09:47:06 2008
@@ -222,3 +222,16 @@
 struct {int a; int:5;} noNamedImplicit[] = {1,2,3};
 int noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1];
 
+
+// ptrs are constant
+struct soft_segment_descriptor {
+	int ssd_base;
+};
+static int dblfault_tss;
+
+union uniao { int ola; } xpto[1];
+
+struct soft_segment_descriptor gdt_segs[] = {
+	{(int) &dblfault_tss},
+	{ (int)xpto},
+};





More information about the cfe-commits mailing list