https://github.com/alexfh created https://github.com/llvm/llvm-project/pull/142988
CXXParenListInitExpr arguments would lose casts leading to incorrect types being used (e.g. only 32 bits of a 64 bit value being initialized). See https://github.com/llvm/llvm-project/pull/138518#issuecomment-2906276916 and https://github.com/llvm/llvm-project/pull/138518#issuecomment-2944538713 for details and context. >From c7154b0b2bd6457d908bb7fbedc028219f8b5e6d Mon Sep 17 00:00:00 2001 From: Alexander Kornienko <ale...@google.com> Date: Thu, 5 Jun 2025 15:10:39 +0000 Subject: [PATCH] Fix an error introduced in #138518 --- clang/lib/Sema/SemaExprCXX.cpp | 5 +++++ clang/test/SemaCXX/paren-list-init-expr.cpp | 23 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 clang/test/SemaCXX/paren-list-init-expr.cpp diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 84521a3f80ff4..516015302bb39 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2160,6 +2160,11 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, "paren init for non-call init"); Exprs = MultiExprArg(List->getExprs(), List->getNumExprs()); } + if (auto *List = dyn_cast_or_null<CXXParenListInitExpr>(Initializer)) { + assert(InitStyle == CXXNewInitializationStyle::Parens && + "paren init for non-call init"); + Exprs = List->getInitExprs(); + } // C++11 [expr.new]p15: // A new-expression that creates an object of type T initializes that diff --git a/clang/test/SemaCXX/paren-list-init-expr.cpp b/clang/test/SemaCXX/paren-list-init-expr.cpp new file mode 100644 index 0000000000000..7d7f46be7a8fd --- /dev/null +++ b/clang/test/SemaCXX/paren-list-init-expr.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s +struct Node { + long val; +}; +template <bool> +void CallNew() { + new Node(0); +} +// CHECK-LABEL: FunctionTemplateDecl {{.*}} CallNew +// CHECK: |-FunctionDecl {{.*}} CallNew 'void ()' +// CHECK: `-CXXNewExpr {{.*}} 'operator new' 'void *(unsigned long)' +// CHECK: `-CXXParenListInitExpr {{.*}} 'Node' +// CHECK: `-ImplicitCastExpr {{.*}} 'long' <IntegralCast> +// CHECK: `-IntegerLiteral {{.*}} 'int' 0 +// CHECK: `-FunctionDecl {{.*}} used CallNew 'void ()' implicit_instantiation +// CHECK: |-TemplateArgument integral 'true' +// CHECK: `-CXXNewExpr {{.*}} 'operator new' 'void *(unsigned long)' +// CHECK: `-CXXParenListInitExpr {{.*}} 'Node' +// CHECK: `-ImplicitCastExpr {{.*}} 'long' <IntegralCast> +// CHECK: `-IntegerLiteral {{.*}} 'int' 0 +void f() { + (void)CallNew<true>; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits