llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alexander Kornienko (alexfh)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/142988.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaExprCXX.cpp (+5) 
- (added) clang/test/SemaCXX/paren-list-init-expr.cpp (+23) 


``````````diff
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>; 
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/142988
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to