llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.91k stars 11.51k forks source link

[Clang]logical-op-parentheses warning is ignored within macro #96036

Open keyihao opened 2 months ago

keyihao commented 2 months ago

With the following minimum case

#include <cstdio>

using namespace std;

int main()
{
#define TEST(v1, v2, v3)       \
    if( v1 && v2 || v3)        \
        printf("hello test\n");  

    bool a=1, b=1, c=1;
    if( a && b || c)                
        printf("hello world\n");
    TEST(a, b,c );                  
    return 0;
}

Both clang 17.0.1 and 18.1.0,clang++ test.cpp -o test -Wall only report 1 warning but ignoring the warning within TEST macro。 image Case: https://godbolt.org/z/8WjWfv8TY

If separate into preprocess and compile phases, the compiler reports 2 warnings exactly. clang++ -E test.cpp -o test.ii -Wall and clang++ -c test.ii -o test.o -Wall image Preprocess output: https://godbolt.org/z/hjM4o7q78 Compile output: https://godbolt.org/z/aM65z5j7f

keyihao commented 2 months ago

In comparison, gcc could report 2 warnings directly with -Wall https://godbolt.org/z/fbsovdbd1 image

keyihao commented 2 months ago

Seems related to https://reviews.llvm.org/D47687?id=150517