[PATCH] Fix to PR5683 - issue diagnostic for pointer subtraction with type of size zero.
Richard Smith
richard at metafoo.co.uk
Tue Aug 27 13:18:09 PDT 2013
================
Comment at: lib/AST/ExprConstant.cpp:6564-6570
@@ -6563,1 +6563,9 @@
+ // As an extension, a type may have zero size (empty struct or union in
+ // C, array of zero length). Meaning of pointer difference in such
+ // case is unspecified.
+ if (ElementSize.isZero()) {
+ Result = APValue(Info.Ctx.MakeIntValue(0, E->getType()));
+ return true;
+ }
+
----------------
Should we really treat the result as a constant zero in this case? GCC treats it as non-constant (and emits a divide-by-zero at runtime.) C++11 requires us to treat expressions with undefined behavior as non-constant.
http://llvm-reviews.chandlerc.com/D637
More information about the cfe-commits
mailing list