Krishna-13-cyber updated this revision to Diff 516397. Krishna-13-cyber added a comment.
- Update with addition of testcase - There is an issue for which the build fails,actually when I replace the diagnostic by `comparison of address of 'x' not equal to a null pointer is always true` in **/clang/test/Sema/conditional-expr.c Line 89**,it shows `C99 forbids conditional expressions with only one void side` and vice versa.It regresses either ways. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D149000/new/ https://reviews.llvm.org/D149000 Files: clang/lib/Sema/SemaChecking.cpp clang/test/Sema/conditional-expr.c clang/test/Sema/warn-tautological-compare.c clang/test/SemaCXX/constant-expression-cxx2a.cpp Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx2a.cpp +++ clang/test/SemaCXX/constant-expression-cxx2a.cpp @@ -249,7 +249,7 @@ // During construction of C, A is unambiguous subobject of dynamic type C. static_assert(g.c == (C*)&g); // ... but in the complete object, the same is not true, so the runtime fails. - static_assert(dynamic_cast<const A*>(static_cast<const C2*>(&g)) == nullptr); + static_assert(dynamic_cast<const A*>(static_cast<const C2*>(&g)) == nullptr); // expected-warning {{comparison of address of 'g' equal to a null pointer is always false}} // dynamic_cast<void*> produces a pointer to the object of the dynamic type. static_assert(g.f == (void*)(F*)&g); Index: clang/test/Sema/warn-tautological-compare.c =================================================================== --- clang/test/Sema/warn-tautological-compare.c +++ clang/test/Sema/warn-tautological-compare.c @@ -93,3 +93,9 @@ x = array ? 1 : 0; // expected-warning {{address of array}} x = &x ? 1 : 0; // expected-warning {{address of 'x'}} } + +void test4(void) +{ +int *a = (void *) 0; +int b = (&a) == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}} +} \ No newline at end of file Index: clang/test/Sema/conditional-expr.c =================================================================== --- clang/test/Sema/conditional-expr.c +++ clang/test/Sema/conditional-expr.c @@ -86,7 +86,7 @@ int Postgresql(void) { char x; - return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}} + return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}} } #define nil ((void*) 0) Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -14723,7 +14723,7 @@ bool IsAddressOf = false; - if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { + if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts())) { if (UO->getOpcode() != UO_AddrOf) return; IsAddressOf = true;
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx2a.cpp +++ clang/test/SemaCXX/constant-expression-cxx2a.cpp @@ -249,7 +249,7 @@ // During construction of C, A is unambiguous subobject of dynamic type C. static_assert(g.c == (C*)&g); // ... but in the complete object, the same is not true, so the runtime fails. - static_assert(dynamic_cast<const A*>(static_cast<const C2*>(&g)) == nullptr); + static_assert(dynamic_cast<const A*>(static_cast<const C2*>(&g)) == nullptr); // expected-warning {{comparison of address of 'g' equal to a null pointer is always false}} // dynamic_cast<void*> produces a pointer to the object of the dynamic type. static_assert(g.f == (void*)(F*)&g); Index: clang/test/Sema/warn-tautological-compare.c =================================================================== --- clang/test/Sema/warn-tautological-compare.c +++ clang/test/Sema/warn-tautological-compare.c @@ -93,3 +93,9 @@ x = array ? 1 : 0; // expected-warning {{address of array}} x = &x ? 1 : 0; // expected-warning {{address of 'x'}} } + +void test4(void) +{ +int *a = (void *) 0; +int b = (&a) == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}} +} \ No newline at end of file Index: clang/test/Sema/conditional-expr.c =================================================================== --- clang/test/Sema/conditional-expr.c +++ clang/test/Sema/conditional-expr.c @@ -86,7 +86,7 @@ int Postgresql(void) { char x; - return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}} + return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}} } #define nil ((void*) 0) Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -14723,7 +14723,7 @@ bool IsAddressOf = false; - if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { + if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts())) { if (UO->getOpcode() != UO_AddrOf) return; IsAddressOf = true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits