Author: Samrudh Nelli Date: 2026-02-17T15:02:20+01:00 New Revision: 19a6a2810ee35724a5967f7780242dbfd677283e
URL: https://github.com/llvm/llvm-project/commit/19a6a2810ee35724a5967f7780242dbfd677283e DIFF: https://github.com/llvm/llvm-project/commit/19a6a2810ee35724a5967f7780242dbfd677283e.diff LOG: [clang] Fix crashes when initializing constexpr int* with floating-point (#180376) Call isNullPointer() only when we are sure that Rvalue is a pointer. Fixes #180313 --------- Co-authored-by: Mariya Podchishchaeva <[email protected]> Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaInit.cpp clang/test/AST/ByteCode/constexpr.c clang/test/Sema/constexpr.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a2cdeb7bc1744..5416b25b3927c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -300,6 +300,7 @@ Miscellaneous Clang Crashes Fixed - Fixed a crash when using loop hint with a value dependent argument inside a generic lambda. (#GH172289) - Fixed a crash in C++ overload resolution with ``_Atomic``-qualified argument types. (#GH170433) +- Fixed a crash when initializing a ``constexpr`` pointer with a floating-point literal in C23. (#GH180313) - Fixed an assertion when diagnosing address-space qualified ``new``/``delete`` in language-defined address spaces such as OpenCL ``__local``. (#GH178319) - Fixed an assertion failure in ObjC++ ARC when binding a rvalue reference to reference with diff erent lifetimes (#GH178524) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 989f7cd80cbef..498ffd0887630 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -8512,8 +8512,9 @@ ExprResult InitializationSequence::Perform(Sema &S, Expr::EvalResult ER; if (Entity.getType()->getAs<PointerType>() && CurInit.get()->EvaluateAsRValue(ER, S.Context) && - !ER.Val.isNullPointer()) { + (ER.Val.isLValue() && !ER.Val.isNullPointer())) { S.Diag(Kind.getLocation(), diag::err_c23_constexpr_pointer_not_null); + return ExprError(); } } diff --git a/clang/test/AST/ByteCode/constexpr.c b/clang/test/AST/ByteCode/constexpr.c index af96bf3a06f37..dfe3d667f27cc 100644 --- a/clang/test/AST/ByteCode/constexpr.c +++ b/clang/test/AST/ByteCode/constexpr.c @@ -309,10 +309,10 @@ constexpr const int *V81 = &V80; constexpr int *V82 = 0; constexpr int *V83 = V82; constexpr int *V84 = 42; -// both-error@-1 {{constexpr variable 'V84' must be initialized by a constant expression}} -// both-note@-2 {{this conversion is not allowed in a constant expression}} -// both-error@-3 {{constexpr pointer initializer is not null}} +// both-error@-1 {{constexpr pointer initializer is not null}} constexpr int *V85 = nullptr; +constexpr int *V91 = 0.; +// both-error@-1 {{initializing 'int *const' with an expression of incompatible type 'double'}} // Check that constexpr variables should not be VLAs. void f6(const int P1) { diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c index ae01c71e09b06..04da0f56a741d 100644 --- a/clang/test/Sema/constexpr.c +++ b/clang/test/Sema/constexpr.c @@ -309,10 +309,10 @@ constexpr const int *V81 = &V80; constexpr int *V82 = 0; constexpr int *V83 = V82; constexpr int *V84 = 42; -// expected-error@-1 {{constexpr variable 'V84' must be initialized by a constant expression}} -// expected-note@-2 {{this conversion is not allowed in a constant expression}} -// expected-error@-3 {{constexpr pointer initializer is not null}} +// expected-error@-1 {{constexpr pointer initializer is not null}} constexpr int *V85 = nullptr; +constexpr int *V91 = 0.0; +// expected-error@-1 {{initializing 'int *const' with an expression of incompatible type 'double'}} // Check that constexpr variables should not be VLAs. void f6(const int P1) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
