@@ -3257,7 +3257,7 @@ ExprResult Sema::ActOnIntegerConstant(SourceLocation Loc, uint64_t Val) {
32573257 unsigned IntSize = Context.getTargetInfo().getIntWidth();
32583258 // HLSL Change Starts - HLSL literal int
32593259 QualType Ty;
3260- if (getLangOpts().HLSL) {
3260+ if (getLangOpts().HLSL && getLangOpts().HLSLVersion < hlsl::LangStd::v202x ) {
32613261 IntSize = 64;
32623262 Ty = Context.LitIntTy;
32633263 } else
@@ -3451,13 +3451,21 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
34513451
34523452 Ty = Context.FloatTy;
34533453 // HLSL Change Starts
3454- else if (getLangOpts().HLSL && !Literal.isLong && !Literal.isHalf)
3454+ else if (getLangOpts().HLSL &&
3455+ getLangOpts().HLSLVersion < hlsl::LangStd::v202x &&
3456+ !Literal.isLong && !Literal.isHalf)
34553457 Ty = Context.LitFloatTy;
3456- else if (getLangOpts().HLSL && Literal.isLong)
3458+ else if (Literal.isLong)
34573459 Ty = Context.DoubleTy;
3458- else if (getLangOpts().HLSL && Literal.isHalf) {
3459- Ty = getLangOpts().UseMinPrecision ? Context.FloatTy : Context.HalfTy;
3460- }
3460+ else if (Literal.isHalf) {
3461+ if (getLangOpts().HLSL &&
3462+ getLangOpts().HLSLVersion < hlsl::LangStd::v202x)
3463+ Ty = getLangOpts().UseMinPrecision ? Context.FloatTy : Context.HalfTy;
3464+ else
3465+ Ty = getLangOpts().UseMinPrecision ? Context.HalfFloatTy
3466+ : Context.HalfTy;
3467+ } else if (getLangOpts().HLSL)
3468+ Ty = Context.FloatTy;
34613469 // HLSL Change Ends
34623470 else if (!Literal.isLong)
34633471 Ty = Context.DoubleTy;
@@ -3480,7 +3488,8 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
34803488 return ExprError();
34813489
34823490 // HLSL Change Starts
3483- } else if (getLangOpts().HLSL) {
3491+ } else if (getLangOpts().HLSL &&
3492+ getLangOpts().HLSLVersion < hlsl::LangStd::v202x) {
34843493 QualType Ty;
34853494 unsigned Width = 64;
34863495 llvm::APInt ResultVal(Width, 0);
@@ -3519,8 +3528,9 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
35193528 } else {
35203529 QualType Ty;
35213530
3531+ // HLSL Change: disable the warning below.
35223532 // 'long long' is a C99 or C++11 feature.
3523- if (!getLangOpts().C99 && Literal.isLongLong) {
3533+ if (!getLangOpts().HLSL && !getLangOpts(). C99 && Literal.isLongLong) {
35243534 if (getLangOpts().CPlusPlus)
35253535 Diag(Tok.getLocation(),
35263536 getLangOpts().CPlusPlus11 ?
@@ -3590,6 +3600,17 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
35903600 }
35913601 }
35923602
3603+ // HLSL Change Begin - Treat `long` literal as `long long`
3604+ // This is a bit hacky. HLSL doesn't really have a `long` or `long long`
3605+ // type so the specification has simplified the suffices. Unfortunately,
3606+ // rather than just treating `ll` as `l` we need to do the inverse. This
3607+ // is because we rely on the MSVC mangling which follows LLP64 (l being
3608+ // 32-bit and ll 64-bit). We should find a better solution to this in
3609+ // Clang.
3610+ if (getLangOpts().HLSL && !Literal.isLongLong)
3611+ Literal.isLongLong = Literal.isLong;
3612+ // HLSL Change End
3613+
35933614 // Are long/unsigned long possibilities?
35943615 if (Ty.isNull() && !Literal.isLongLong) {
35953616 unsigned LongSize = Context.getTargetInfo().getLongWidth();
@@ -3603,7 +3624,9 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
36033624 Ty = Context.UnsignedLongTy;
36043625 // Check according to the rules of C90 6.1.3.2p5. C++03 [lex.icon]p2
36053626 // is compatible.
3606- else if (!getLangOpts().C99 && !getLangOpts().CPlusPlus11) {
3627+ // HLSL Change: HLSL will promote to the next signed integer type.
3628+ else if (!getLangOpts().HLSL && !getLangOpts().C99 &&
3629+ !getLangOpts().CPlusPlus11) {
36073630 const unsigned LongLongSize =
36083631 Context.getTargetInfo().getLongLongWidth();
36093632 Diag(Tok.getLocation(),
@@ -6319,8 +6342,17 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
63196342
63206343 // HLSL Change Starts: HLSL supports a vector condition and is
63216344 // sufficiently different to merit its own checker.
6322- if (getLangOpts().HLSL)
6323- return hlsl::CheckVectorConditional(this, Cond, LHS, RHS, QuestionLoc);
6345+ if (getLangOpts().HLSL) {
6346+ // For HLSL 202x+ in a ternary operator we follow C++ rules unless both the
6347+ // right and left are minimum precision types, or either type is not a
6348+ // builtin scalar integer or float (e.g. vector, matrix, UDT).
6349+ QualType LHSTy = LHS.get()->getType();
6350+ QualType RHSTy = RHS.get()->getType();
6351+ if (getLangOpts().HLSLVersion < hlsl::LangStd::v202x ||
6352+ !LHSTy->isBuiltinType() || !RHSTy->isBuiltinType() ||
6353+ (hlsl::IsHLSLMinPrecision(LHSTy) && hlsl::IsHLSLMinPrecision(RHSTy)))
6354+ return hlsl::CheckVectorConditional(this, Cond, LHS, RHS, QuestionLoc);
6355+ }
63246356 // HLSL Change Ends
63256357
63266358 // C++ is sufficiently different to merit its own checker.
0 commit comments