This is an archive of the discontinued LLVM Phabricator instance.

[clang] removes check against integral-to-pointer conversion...
ClosedPublic

Authored by cjdb on Feb 25 2021, 4:13 PM.

Details

Summary

... unless it's a literal

D94640 was a bit too aggressive in its analysis, considering integers
representing valid addresses as invalid. This change rolls back some of
the check, so that only the most obvious case is still flagged.

Before:

cpp
free((void*)1000);   // literal converted to `void*`: warning good
free((void*)an_int); // `int` object converted to `void*`: warning might
                     //  be a false positive

After

cpp
free((void*)1000);   // literal converted to `void*`: warning good
free((void*)an_int); // doesn't warn

Diff Detail

Event Timeline

cjdb requested review of this revision.Feb 25 2021, 4:13 PM
cjdb created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2021, 4:13 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Patch is missing a description of the problem.

cjdb updated this revision to Diff 326723.Feb 26 2021, 9:27 AM
cjdb edited the summary of this revision. (Show Details)

updates commit message to explain what's going on and why the change

aaron.ballman added inline comments.Feb 26 2021, 10:13 AM
clang/lib/Sema/SemaChecking.cpp
10320

We don't typically use top-level const on locals or params.

10326

I'm not 100% certain, but would IgnoreParenImpCasts() be sufficient here? (`IgnoreImplicitAsWritten() seems to be a bit special -- the only use of it I can find in tree is for rewritten binary operator expressions.)

clang/test/Analysis/free.cpp
221

I think it'd be useful to add tests for named casts as well as the C-style casts.

cjdb updated this revision to Diff 326742.Feb 26 2021, 11:01 AM
cjdb marked 2 inline comments as done.

applies comments

cjdb added a subscriber: rsmith.Feb 26 2021, 11:02 AM
cjdb added inline comments.
clang/lib/Sema/SemaChecking.cpp
10320

This makes Christopher sad :(

10326

@rsmith would you mind weighing in here please? My original use-case for IgnoreImplicitAsWritten might be different to here and I don't have an answer for @aaron.ballman.

clang/test/Analysis/free.cpp
221

Great idea!

cjdb updated this revision to Diff 326748.Feb 26 2021, 11:11 AM

s/IgnoreImplicitAsWritten/IgnoreParenImpCasts/ since the latter seems to work.

cjdb marked an inline comment as done.Feb 26 2021, 11:12 AM
cjdb added inline comments.
clang/lib/Sema/SemaChecking.cpp
10326

I've tried out IgnoreParenImpCasts and it seems to work, but I'd appreciate an answer here for future patches please.

thakis added a subscriber: thakis.Mar 3 2021, 8:03 AM
thakis added inline comments.
clang/lib/Sema/SemaChecking.cpp
10326

Can you rephrase your question? I'm not sure what exactly you want to know.

cjdb added inline comments.Mar 3 2021, 2:55 PM
clang/lib/Sema/SemaChecking.cpp
10326

Richard suggested I use IgnoreImplicitAsWritten in D94640, but it's apparently unnecessary in D97512. I'd like to better understand when to use IgnoreImplicitAsWritten. (BTW this is non-blocking, so if there are no other comments that need addressing, I'd like to press forward please.)

aaron.ballman accepted this revision.Mar 4 2021, 4:06 AM

LGTM! I think we can resolve the question of which way to ignore implicit nodes and make any necessary changes post-commit.

This revision is now accepted and ready to land.Mar 4 2021, 4:06 AM