[PATCH] Fix to PR5683 - issue diagnostic for pointer subtraction with type of size zero.

Richard Smith richard at metafoo.co.uk
Wed Jun 19 20:25:53 PDT 2013



================
Comment at: lib/AST/ExprConstant.cpp:5006-5010
@@ -5005,1 +5005,7 @@
 
+        // Empty struct or union in C has size 0 (GCC extension). Meaning of
+        // pointer difference in such case is unspecified, so set ElementSize
+        // to 1 to avoid division by zero.
+        if (ElementSize.isZero())
+            ElementSize = CharUnits::One();
+
----------------
If behavior is undefined here, we should just refuse to evaluate the expression as a constant. Produce a diagnostic (with Info.Diag(E, diag::note_whatever)) and return false.


http://llvm-reviews.chandlerc.com/D637



More information about the cfe-commits mailing list