Skip to content

Commit ef1cff1

Browse files
authored
Set SourceLocation for begin/end of initlist for hlsl. (#4091)
* Set SourceLocation for begin/end of initlist for hlsl. * Add VectorInitWithCXXFunctionalCastExpr to mark vector init like float4(a, b, c, d).
1 parent 31b15e3 commit ef1cff1

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

tools/clang/include/clang/AST/Expr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,13 @@ class InitListExpr : public Expr {
39103910
InitListExprBits.HadArrayRangeDesignator = ARD;
39113911
}
39123912

3913+
bool isVectorInitWithCXXFunctionalCastExpr() const {
3914+
return InitListExprBits.VectorInitWithCXXFunctionalCastExpr != 0;
3915+
}
3916+
void sawVectorInitWithCXXFunctionalCastExpr(bool InitWithCast) {
3917+
InitListExprBits.VectorInitWithCXXFunctionalCastExpr = InitWithCast;
3918+
}
3919+
39133920
SourceLocation getLocStart() const LLVM_READONLY;
39143921
SourceLocation getLocEnd() const LLVM_READONLY;
39153922

tools/clang/include/clang/AST/Stmt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ class LLVM_ALIGNAS(LLVM_PTR_SIZE) Stmt {
272272
/// Whether this initializer list originally had a GNU array-range
273273
/// designator in it. This is a temporary marker used by CodeGen.
274274
unsigned HadArrayRangeDesignator : 1;
275+
// HLSL Change begin - mark vector init like float4(a,b,c,d).
276+
unsigned VectorInitWithCXXFunctionalCastExpr : 1;
277+
// HLSL Change end.
275278
};
276279

277280
class TypeTraitExprBitfields {

tools/clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
19211921
LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(nullptr, true)
19221922
{
19231923
sawArrayRangeDesignator(false);
1924+
sawVectorInitWithCXXFunctionalCastExpr(false); // HLSL change.
19241925
for (unsigned I = 0; I != initExprs.size(); ++I) {
19251926
if (initExprs[I]->isTypeDependent())
19261927
ExprBits.TypeDependent = true;

tools/clang/lib/AST/StmtPrinter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,8 @@ void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
14791479
return;
14801480
}
14811481

1482-
if (!Policy.LangOpts.HLSL || (Node->getLBraceLoc().isValid() || Node->getRBraceLoc().isValid())) // HLSL Change
1482+
if (!Policy.LangOpts.HLSL ||
1483+
!Node->isVectorInitWithCXXFunctionalCastExpr()) // HLSL Change
14831484
OS << "{ ";
14841485

14851486
for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
@@ -1490,7 +1491,8 @@ void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
14901491
OS << "{}";
14911492
}
14921493

1493-
if (!Policy.LangOpts.HLSL || (Node->getLBraceLoc().isValid() || Node->getRBraceLoc().isValid())) // HLSL Change
1494+
if (!Policy.LangOpts.HLSL ||
1495+
!Node->isVectorInitWithCXXFunctionalCastExpr()) // HLSL Change
14941496
OS << " }";
14951497
}
14961498

tools/clang/lib/Sema/SemaInit.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6183,7 +6183,11 @@ InitializationSequence::Perform(Sema &S,
61836183
CK_LValueToRValue, Args[i], /*BasePath=*/0, VK_RValue);
61846184
}
61856185
}
6186-
CurInit = new (S.getASTContext())InitListExpr(S.getASTContext(), SourceLocation(), Args, SourceLocation());
6186+
InitListExpr *castInit = new (S.getASTContext())
6187+
InitListExpr(S.getASTContext(), Kind.getParenRange().getBegin(), Args,
6188+
Kind.getParenRange().getEnd());
6189+
castInit->sawVectorInitWithCXXFunctionalCastExpr(true);
6190+
CurInit = castInit;
61876191
}
61886192
break;
61896193
}

tools/clang/test/CodeGenSPIRV/spirv.debug.opline.composite.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void main() {
5757
};
5858

5959
// CHECK: OpFDiv %float {{%\d+}} %float_2
60-
// CHECK-NEXT: OpLine [[file]] 64 25
60+
// CHECK-NEXT: OpLine [[file]] 64 24
6161
// CHECK-NEXT: [[first:%\d+]] = OpCompositeConstruct %v2float {{%\d+}} {{%\d+}}
6262
// CHECK-NEXT: [[second:%\d+]] = OpCompositeConstruct %v2float {{%\d+}} {{%\d+}}
6363
// CHECK-NEXT: {{%\d+}} = OpCompositeConstruct %mat2v2float [[first]] [[second]]
@@ -104,7 +104,7 @@ void main() {
104104
// CHECK-NEXT: OpConvertFToS %int
105105
int4 e = {1, 2, bar};
106106

107-
// CHECK: OpLine [[file]] 111 16
107+
// CHECK: OpLine [[file]] 111 15
108108
// CHECK-NEXT: OpCompositeConstruct %v2float %float_1 %float_2
109109
// CHECK-NEXT: OpLine [[file]] 111 22
110110
// CHECK-NEXT: OpCompositeExtract %int

0 commit comments

Comments
 (0)