[PATCH] D55862: [Sema] Don't try to account for the size of an incomplete type in CheckArrayAccess

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 18 16:40:13 PST 2018

efriedma added inline comments.

Comment at: lib/Sema/SemaChecking.cpp:12381
+    // It is possible that the base type is incomplete (see PR39746), even
+    // though the effective type is complete. In this case we have no info
+    // about the size of the base type and so skip the following adjustment.
This comment is really confusing; the meaning of "base type" and "effective type" in this context isn't clear.  Also, "effective type" is a term defined in the C standard to mean something else.  Better to explicitly say you're talking about the type of the base expression before/after the call to IgnoreParenCasts.

Comment at: lib/Sema/SemaChecking.cpp:12383
+    // about the size of the base type and so skip the following adjustment.
+    if ((BaseType != EffectiveType) && !BaseType->isIncompleteType(nullptr)) {
       // Make sure we're comparing apples to apples when comparing index to size
You don't need to explicitly pass nullptr here; there's a default argument.

Comment at: test/SemaCXX/array-bounds.cpp:294
+  C &f() { return reinterpret_cast<C *>(xxx)[1]; } // no-warning
+  C &g() { return reinterpret_cast<C *>(xxx)[2]; } // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
Not sure it actually makes sense to print a diagnostic here... at least, not this diagnostic.  We don't know whether the result here is actually out of bounds.

  rC Clang



More information about the cfe-commits mailing list