This is an archive of the discontinued LLVM Phabricator instance.

Cleanup MemRegion.cpp/MemRegion.h
ClosedPublic

Authored by ariccio on Jan 29 2016, 10:45 PM.

Details

Summary

There are lots of (a) unnecessary, and (b) C-style, casts in MemRegion.cpp, and they were giving me a headache. I also noticed and fixed two non-const member functions.

I also did one drive-by fix where a conditional break was inside an unbraced loop. Code like that is always harder to read, and easily breakable.

Not exactly sure who to add here, so please redirect if you know who is? Looks like dcoughlin, aaron.ballman, and dergachev, are good bets, as they're in previous revisions.

Diff Detail

Event Timeline

ariccio updated this revision to Diff 46468.Jan 29 2016, 10:45 PM
ariccio retitled this revision from to Cleanup MemRegion.cpp/MemRegion.h.
ariccio updated this object.

All checks - except the two that normally don't in my environment - pass! Adding reviewers.

This looks fine to me, except please be careful about extra spaces. Thanks for cleaning this up!

Adding Anna Zaks as a reviewer since she is the code owner for the static analyzer.

C:/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
253

Extra space here.

258

Extra space here.

265

Extra space here.

273

Extra space here.

281

Extra space here.

298

Extra space here.

338

Extra space here.

457

Extra spaces here.

465

Extra spaces here.

481

Extra spaces here.

486

Extra spaces here.

Oops. The funny thing about the extra spaces is that I wasn't sure why there were spaces after the casts already, so I figured that I should keep it that way.

I shall fix.

ariccio updated this revision to Diff 46481.Jan 30 2016, 10:39 PM
ariccio edited edge metadata.
ariccio marked 10 inline comments as done.

Removed extra spaces.

aaron.ballman accepted this revision.Feb 1 2016, 6:58 AM
aaron.ballman edited edge metadata.

Aside from one minor nit with auto usage, LGTM!

C:/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
1396

No need for a const here; the correct change is to not use auto (here and the line above), but instead spell out the type explicitly.

This revision is now accepted and ready to land.Feb 1 2016, 6:58 AM
ariccio marked an inline comment as done.Feb 1 2016, 1:19 PM

As said in comment, I disagree with the no need for const here.

C:/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
1396

The const is partly to make sure that the if (NumBlockVars == 0) { line never accidentally becomes if (NumBlockVars = 0) { like it did in CPython:

http://bugs.python.org/issue25844

1396

For archival reasons, I'll copy & paste the relevant diff here (I hate dead links):

--- a/PC/launcher.c
+++ b/PC/launcher.c
@@ -114,7 +114,7 @@ static wchar_t * get_env(wchar_t * key)
     if (result >= BUFSIZE) {
         /* Large environment variable. Accept some leakage */
         wchar_t *buf2 = (wchar_t*)malloc(sizeof(wchar_t) * (result+1));
-        if (buf2 = NULL) {
+        if (buf2 == NULL) {
             error(RC_NO_MEMORY, L"Could not allocate environment buffer");
         }
         GetEnvironmentVariableW(key, buf2, result);
aaron.ballman added inline comments.Feb 1 2016, 1:26 PM
C:/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
1396

While this form of bug can certainly crop up, it's still a bridge-too-far for this project, as I understand it our de facto guidelines on this. I am not certain that we want to start sprinkling const onto value types (as opposed to reference and pointer types) at this point. If we do, it should certainly be something handled a bit more consistently and actively than a general clean-up related to unnecessary type casting.

ariccio marked 3 inline comments as done.Feb 2 2016, 5:15 PM

I will remove that const later tonight.

C:/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
1396

If we do, it should certainly be something handled a bit more consistently and actively than a general clean-up related to unnecessary type casting.

You've got a good point there. I'll upload a final revision without that const a bit later tonight.

ariccio updated this revision to Diff 46737.Feb 2 2016, 8:53 PM
ariccio edited edge metadata.
ariccio marked 2 inline comments as done.

Removed single const.

aaron.ballman closed this revision.Feb 3 2016, 7:25 AM

LGTM, but the patch does not apply cleanly because it was created using absolute paths. In the future, please generate the patch with relative paths. ;-)

Commit in r259652

LGTM, but the patch does not apply cleanly because it was created using absolute paths. In the future, please generate the patch with relative paths. ;-)

Commit in r259652

Oops.

ariccio marked an inline comment as done.Feb 3 2016, 4:07 PM

Grr! missed a single note.