This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by riccibruno on Dec 18 2018, 3:43 PM.

Details

Summary

When checking that the array access is not out-of-bounds in CheckArrayAccess,
it is possible that the type of the base expression after IgnoreParenCasts is incomplete,
even though the type of the base expression before IgnoreParenCasts is complete
In this case we have no information about whether the array access is out-of-bounds,
and we should just bail-out instead. This fixes PR39746 which was caused by trying
to obtain the size of an incomplete type.

Diff Detail

Repository
rL LLVM

Event Timeline

riccibruno created this revision.Dec 18 2018, 3:43 PM
efriedma added inline comments.Dec 18 2018, 4:40 PM
lib/Sema/SemaChecking.cpp
12381 ↗(On Diff #178807)

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.

12383 ↗(On Diff #178807)

You don't need to explicitly pass nullptr here; there's a default argument.

test/SemaCXX/array-bounds.cpp
294 ↗(On Diff #178807)

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.

riccibruno marked 4 inline comments as done.
riccibruno added inline comments.
test/SemaCXX/array-bounds.cpp
294 ↗(On Diff #178807)

Right. I think that the right thing to do then is to not print anything
since we really don't have any information about whether this
is out of bounds.

riccibruno edited the summary of this revision. (Show Details)Dec 19 2018, 5:35 AM
efriedma added inline comments.Dec 19 2018, 11:45 AM
lib/Sema/SemaChecking.cpp
12357 ↗(On Diff #178848)

Using getPointeeOrArrayElementType here is kind of confusing; instead, we can just call ArrayTy->getElementType().

Used ArrayTy->getElementType()

riccibruno marked an inline comment as done.Dec 20 2018, 3:42 AM
This revision is now accepted and ready to land.Dec 20 2018, 11:24 AM
This revision was automatically updated to reflect the committed changes.