[PATCH] D65287: [analyzer][CFG] Don't track the condition of asserts

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 25 13:50:50 PDT 2019


NoQ added a comment.

I'm sure i've seen something with a do-while(0) loop. Let's also add the following:

  #define assert(x) do {                                    \
    if (!x)                                                 \
      __assert_fail (#expr, __FILE__, __LINE__, __func__)   \
  } while (0)



================
Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1753-1755
+  // It so happens that CFGBlock::getTerminatorCondition returns 'A' for block
+  // B1, 'A && B' for B2, and 'A && B || C' for B3. Let's check whether we
+  // reached the end of the condition!
----------------
Clever trick, but why not match for logical operators directly? Something like this:
```lang=c++
if (auto B = dyn_cast<BinaryOperator>(OuterCond))
  if (B->isLogicalOp())
    return isAssertlikeBlock(Else, Context);
```


================
Comment at: clang/test/Analysis/track-control-dependency-conditions.cpp:469-471
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+                           unsigned int __line, __const char *__function)
+__attribute__ ((__noreturn__));
----------------
I'm pretty sure you can define this function only once.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65287/new/

https://reviews.llvm.org/D65287





More information about the cfe-commits mailing list