[cfe-dev] Best way to determine if preprocessor directives live in a source range?

Richard legalize at xmission.com
Sun May 24 17:07:30 PDT 2015

I'm enhancing clang-tidy to replace:

    if (expr)
      return true;
    return false;


    return expr;

I am running the transformation on the LLVM/clang code as a test bed.
In the course of examining the results it turned up this one in


 /// Test if a floating-point exception was raised.
 static inline bool llvm_fenv_testexcept() {
   int errno_val = errno;
-  if (errno_val == ERANGE || errno_val == EDOM)
-    return true;
-  if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
-    return true;
-  return false;
+  return errno_val == ERANGE || errno_val == EDOM;
 } // End namespace

Clearly, this is not behavior preserving.  According to the AST, the
part that is #if'ed out doesn't exist.

What's the best way to identify such things so that the tool's default
behavior would be to leave these alone?

PS: Mail filters are blocking my messages, so ignore this, its
only for them.  Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Phasellus consequat ullamcorper mollis. Sed blandit semper tortor
ultricies dictum. Proin hendrerit et quam in sagittis. Maecenas vel
blandit ante, in auctor sem.  Phasellus condimentum leo vel finibus
viverra. Duis fermentum sollicitudin est, ac iaculis lectus auctor vel.
Nam condimentum nulla feugiat, venenatis nibh a, elementum nulla. Nulla
vitae malesuada eros. Nulla cursus maximus ligula non hendrerit.

Curabitur lobortis nulla vel sapien posuere, id aliquam orci
bibendum. Vestibulum at vulputate risus. Proin in purus commodo,
tempus lectus vitae, faucibus nunc. Aenean congue faucibus elit, sit
amet facilisis nibh ultrices eget. Nam pulvinar leo ac nunc ultricies,
nec tincidunt nulla tincidunt. Etiam placerat felis tellus, ut ultricies
nunc ultricies quis. In placerat sapien nec ultricies mattis. Integer
sed tempor orci, ac imperdiet orci. Integer ac augue et augue convallis
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>

More information about the cfe-dev mailing list