xbolva00 created this revision. xbolva00 added reviewers: aaron.ballman, rsmith. xbolva00 added a project: clang. Herald added subscribers: libcxx-commits, christof. Herald added a project: libc++.
Clang should not warn for: test.c:2:12: warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference] return *(int __attribute__((address_space(256))) *) 0; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Solves PR42292. [libcxx] Disable -Wconstant-evaluated for libcxx's testsuite Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D69706 Files: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/exprs.c libcxx/utils/libcxx/test/config.py Index: libcxx/utils/libcxx/test/config.py =================================================================== --- libcxx/utils/libcxx/test/config.py +++ libcxx/utils/libcxx/test/config.py @@ -915,6 +915,7 @@ self.cxx.addWarningFlagIfSupported('-Wshadow') self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument') self.cxx.addWarningFlagIfSupported('-Wno-attributes') + self.cxx.addWarningFlagIfSupported('-Wno-constant-evaluated') self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move') self.cxx.addWarningFlagIfSupported('-Wno-c++11-extensions') self.cxx.addWarningFlagIfSupported('-Wno-user-defined-literals') Index: clang/test/Sema/exprs.c =================================================================== --- clang/test/Sema/exprs.c +++ clang/test/Sema/exprs.c @@ -179,11 +179,14 @@ test18_e(); // expected-error {{too few arguments to function call, expected at least 2, have 0}} } +typedef int __attribute__((address_space(256))) int_AS256; // PR7569 void test19() { *(int*)0 = 0; // expected-warning {{indirection of non-volatile null pointer}} \ // expected-note {{consider using __builtin_trap}} *(volatile int*)0 = 0; // Ok. + *(int __attribute__((address_space(256))) *)0 = 0; // Ok. + *(int_AS256*)0 = 0; // Ok. // rdar://9269271 int x = *(int*)0; // expected-warning {{indirection of non-volatile null pointer}} \ Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -483,15 +483,17 @@ // only handles the pattern "*null", which is a very syntactic check. if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts())) if (UO->getOpcode() == UO_Deref && - UO->getSubExpr()->IgnoreParenCasts()-> - isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull) && + !isTargetAddressSpace( + UO->getSubExpr()->getType()->getPointeeType().getAddressSpace()) && + UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant( + S.Context, Expr::NPC_ValueDependentIsNotNull) && !UO->getType().isVolatileQualified()) { - S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, - S.PDiag(diag::warn_indirection_through_null) - << UO->getSubExpr()->getSourceRange()); - S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, - S.PDiag(diag::note_indirection_through_null)); - } + S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, + S.PDiag(diag::warn_indirection_through_null) + << UO->getSubExpr()->getSourceRange()); + S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, + S.PDiag(diag::note_indirection_through_null)); + } } static void DiagnoseDirectIsaAccess(Sema &S, const ObjCIvarRefExpr *OIRE,
Index: libcxx/utils/libcxx/test/config.py =================================================================== --- libcxx/utils/libcxx/test/config.py +++ libcxx/utils/libcxx/test/config.py @@ -915,6 +915,7 @@ self.cxx.addWarningFlagIfSupported('-Wshadow') self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument') self.cxx.addWarningFlagIfSupported('-Wno-attributes') + self.cxx.addWarningFlagIfSupported('-Wno-constant-evaluated') self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move') self.cxx.addWarningFlagIfSupported('-Wno-c++11-extensions') self.cxx.addWarningFlagIfSupported('-Wno-user-defined-literals') Index: clang/test/Sema/exprs.c =================================================================== --- clang/test/Sema/exprs.c +++ clang/test/Sema/exprs.c @@ -179,11 +179,14 @@ test18_e(); // expected-error {{too few arguments to function call, expected at least 2, have 0}} } +typedef int __attribute__((address_space(256))) int_AS256; // PR7569 void test19() { *(int*)0 = 0; // expected-warning {{indirection of non-volatile null pointer}} \ // expected-note {{consider using __builtin_trap}} *(volatile int*)0 = 0; // Ok. + *(int __attribute__((address_space(256))) *)0 = 0; // Ok. + *(int_AS256*)0 = 0; // Ok. // rdar://9269271 int x = *(int*)0; // expected-warning {{indirection of non-volatile null pointer}} \ Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -483,15 +483,17 @@ // only handles the pattern "*null", which is a very syntactic check. if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts())) if (UO->getOpcode() == UO_Deref && - UO->getSubExpr()->IgnoreParenCasts()-> - isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull) && + !isTargetAddressSpace( + UO->getSubExpr()->getType()->getPointeeType().getAddressSpace()) && + UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant( + S.Context, Expr::NPC_ValueDependentIsNotNull) && !UO->getType().isVolatileQualified()) { - S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, - S.PDiag(diag::warn_indirection_through_null) - << UO->getSubExpr()->getSourceRange()); - S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, - S.PDiag(diag::note_indirection_through_null)); - } + S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, + S.PDiag(diag::warn_indirection_through_null) + << UO->getSubExpr()->getSourceRange()); + S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, + S.PDiag(diag::note_indirection_through_null)); + } } static void DiagnoseDirectIsaAccess(Sema &S, const ObjCIvarRefExpr *OIRE,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits