Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ line upon naming the release. Refer to previous for appropriate section names.
[#8964](https://github.com/microsoft/DirectXShaderCompiler/issues/8964).
- Add `static_assert` matching C++11 and C++17 under HLSL 202x
([#8910](https://github.com/microsoft/DirectXShaderCompiler/issues/8910)).
- Fix HLSL 202x conforming literals false-positive warning for hex literal
signedness
([#7864](https://github.com/microsoft/DirectXShaderCompiler/issues/7864)).

#### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions tools/clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3540,7 +3540,7 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
if (Val < std::numeric_limits<uint32_t>::max())
Width = 32;
uint64_t MSB = 1ull << (Width - 1);
if ((Val & MSB) != 0)
if (!Literal.isUnsigned && (Val & MSB) != 0)
Comment thread
llvm-beanz marked this conversation as resolved.
Diag(Tok.getLocation(),
diag::warn_hlsl_legacy_integer_literal_signedness);
}
Expand Down Expand Up @@ -3702,7 +3702,7 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
// HLSL Change Begin - 202x integer warnings.
if (Literal.getRadix() != 10) {
uint64_t Val = ResultVal.getLimitedValue();
if ((Val & MSB) != 0)
if (!Literal.isUnsigned && (Val & MSB) != 0)
Diag(Tok.getLocation(),
diag::warn_hlsl_legacy_integer_literal_signedness);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ _Static_assert(is_same<__decltype(0x7000000000000000), int64_t>::value, "0x70000
// expected-warning@+1{{literal value is treated as signed in HLSL 2021 and earlier, and unsigned in later language versions}}
_Static_assert(is_same<__decltype(0xF000000000000000), uint64_t>::value, "0xF000000000000000 is uint64_t");

static const uint Suffixed = 0xFFF00000u; // No warning here!
// expected-warning@+1{{literal value is treated as signed in HLSL 2021 and earlier, and unsigned in later language versions}}
static const uint CastedUnsigned = (uint)0xFFF00000;
// expected-warning@+1{{literal value is treated as signed in HLSL 2021 and earlier, and unsigned in later language versions}}
static const int CastedSigned = (int)0xFFF00000;
Comment thread
Copilot marked this conversation as resolved.

#else
// The `literal float` typename is not spellable so we cannot verify the truth
// in this way.
Expand Down Expand Up @@ -118,6 +124,12 @@ uint OctSignedBitMask32() {
uint64_t OctSignedBitMask64() {
return 0400000000000000000000; // No warning
}

static const uint Suffixed = 0xFFF00000u; // No warning here!
// expected-warning@+1{{literal value is treated as signed in HLSL 2021 and earlier, and unsigned in later language versions}}
static const uint CastedUnsigned = (uint)0xFFF00000;
// expected-warning@+1{{literal value is treated as signed in HLSL 2021 and earlier, and unsigned in later language versions}}
static const int CastedSigned = (int)0xFFF00000;
#endif

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading