[cfe-commits] r55627 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/init.c
Eli Friedman
eli.friedman at gmail.com
Tue Sep 2 02:37:01 PDT 2008
Author: efriedma
Date: Tue Sep 2 04:37:00 2008
New Revision: 55627
URL: http://llvm.org/viewvc/llvm-project?rev=55627&view=rev
Log:
Fix for PR2747: allow pointer->int casts with a null base; these are
offset-of-like expressions.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=55627&r1=55626&r2=55627&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 2 04:37:00 2008
@@ -1163,6 +1163,13 @@
if (SubExpr->getType()->isArithmeticType())
return CheckArithmeticConstantExpression(SubExpr);
+ if (SubExpr->getType()->isPointerType()) {
+ const Expr* Base = FindExpressionBaseAddress(SubExpr);
+ // If the pointer has a null base, this is an offsetof-like construct
+ if (!Base)
+ return CheckAddressConstantExpression(SubExpr);
+ }
+
Diag(Init->getExprLoc(),
diag::err_init_element_not_constant, Init->getSourceRange());
return true;
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=55627&r1=55626&r2=55627&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Tue Sep 2 04:37:00 2008
@@ -58,3 +58,11 @@
int f3(int x) { return x; }
typedef void (*vfunc)(void);
void *bar = (vfunc) f3;
+
+// PR2747
+struct sym_reg {
+ char nc_gpreg;
+};
+int sym_fw1a_scr[] = {
+ ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0
+};
More information about the cfe-commits
mailing list