Skip to content

Commit f532167

Browse files
authored
Fix an error introduced in #138518 (#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 #138518 (comment) and #138518 (comment) for details and context.
1 parent 752adc3 commit f532167

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,10 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
21592159
assert(InitStyle == CXXNewInitializationStyle::Parens &&
21602160
"paren init for non-call init");
21612161
Exprs = MultiExprArg(List->getExprs(), List->getNumExprs());
2162+
} else if (auto *List = dyn_cast_or_null<CXXParenListInitExpr>(Initializer)) {
2163+
assert(InitStyle == CXXNewInitializationStyle::Parens &&
2164+
"paren init for non-call init");
2165+
Exprs = List->getInitExprs();
21622166
}
21632167

21642168
// C++11 [expr.new]p15:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s
2+
struct Node {
3+
long val;
4+
};
5+
template <bool>
6+
void CallNew() {
7+
new Node(0);
8+
}
9+
// CHECK-LABEL: FunctionTemplateDecl {{.*}} CallNew
10+
// CHECK: |-FunctionDecl {{.*}} CallNew 'void ()'
11+
// CHECK: `-CXXNewExpr {{.*}} 'operator new'
12+
// CHECK: `-CXXParenListInitExpr {{.*}} 'Node'
13+
// CHECK: `-ImplicitCastExpr {{.*}} 'long' <IntegralCast>
14+
// CHECK: `-IntegerLiteral {{.*}} 'int' 0
15+
// CHECK: `-FunctionDecl {{.*}} used CallNew 'void ()' implicit_instantiation
16+
// CHECK: |-TemplateArgument integral 'true'
17+
// CHECK: `-CXXNewExpr {{.*}} 'operator new'
18+
// CHECK: `-CXXParenListInitExpr {{.*}} 'Node'
19+
// CHECK: `-ImplicitCastExpr {{.*}} 'long' <IntegralCast>
20+
// CHECK: `-IntegerLiteral {{.*}} 'int' 0
21+
void f() {
22+
(void)CallNew<true>;
23+
}

0 commit comments

Comments
 (0)