Extend IdenticalExprChecker to find more potential problems

Daniel Fahlgren daniel at fahlgren.se
Wed Jan 29 23:30:43 PST 2014


Hi,

This patch extends the identical expression checker to find more places
where you have code duplication, or copy and paste errors. It will now
find if you check the same thing multiple times in a logical expression.
E.g.

  if (a == 1 || a == 1)

It will also detect if you have used the same symbol multiple times when
using bitwise operators. E.g.

  int b = a | a;

The last addition is that it checks if both branches in an if-statement
are identical. E.g.

  if (...)
    a = 1;
  else
    a = 1;


Since this is my first patch I'm sure I've forgotten something. Feedback
is welcome.


For revision 200460 of the llvm tree it actually gives the following
warnings:

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:428:54: warning:
identical expressions on both sides of bitwise operator
    result |= (icmp_eq ? (FoldMskICmp_Mask_AllZeroes |
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:432:57: warning:
identical expressions on both sides of bitwise operator
                       : (FoldMskICmp_Mask_NotAllZeroes |
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^

llvm/lib/IR/ConstantFold.cpp:936:12: warning: true and false branches
are identical
      else if (isa<UndefValue>(C1)) 
           ^

llvm/tools/clang/lib/Basic/Targets.cpp:981:22: warning: identical
expressions on both sides of bitwise operator
                     | ArchDefinePwr6 | ArchDefinePpcgr |
ArchDefinePpcsq)
                     ^ ~~~~~~~~~~~~~~
llvm/tools/clang/lib/Basic/Targets.cpp:995:24: warning: identical
expressions on both sides of bitwise operator
                       | ArchDefinePwr6 | ArchDefinePpcgr |
ArchDefinePpcsq)
                       ^ ~~~~~~~~~~~~~~


Best regards,
Daniel Fahlgren
-------------- next part --------------
A non-text attachment was scrubbed...
Name: identical.patch
Type: text/x-patch
Size: 20445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140130/f677cd3d/attachment.bin>


More information about the cfe-commits mailing list