-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MC][DecoderEmitter] Fix build warning: explicit specialization cannot have a storage class #156375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MC][DecoderEmitter] Fix build warning: explicit specialization cannot have a storage class #156375
Conversation
Seems to build locally for me. |
Will wait for checks before committing |
:( That does not work. What seems to work is moving |
ac7be1e
to
bbb8c98
Compare
Attempt #2..lets see how it goes |
What are the symptoms? Not sure what difference does anonymous namespace make. |
Attempt 1: Linker error with just dropping the static in front of these. Because we now have duplicate template instantiations between RISCV and AMDGPU and they conflict. Attempt 2: Current PR: |
bbb8c98
to
72a94fa
Compare
Its weird though that these are just regular pre-commit checks that are failing once I committed the change. Why did my PR pass the pre-commit checks which run these same checks? |
@llvm/pr-subscribers-tablegen @llvm/pr-subscribers-backend-risc-v Author: Rahul Joshi (jurahul) ChangesMove Full diff: https://github.com/llvm/llvm-project/pull/156375.diff 4 Files Affected:
diff --git a/llvm/include/llvm/MC/MCDecoder.h b/llvm/include/llvm/MC/MCDecoder.h
index 459c8a6a5ea34..87df6c10d8bb2 100644
--- a/llvm/include/llvm/MC/MCDecoder.h
+++ b/llvm/include/llvm/MC/MCDecoder.h
@@ -72,13 +72,6 @@ insertBits(IntType &field, IntType bits, unsigned startBit, unsigned numBits) {
field |= bits << startBit;
}
-// InsnBitWidth is essentially a type trait used by the decoder emitter to query
-// the supported bitwidth for a given type. But default, the value is 0, making
-// it an invalid type for use as `InsnType` when instantiating the decoder.
-// Individual targets are expected to provide specializations for these based
-// on their usage.
-template <typename T> static constexpr uint32_t InsnBitWidth = 0;
-
} // namespace llvm::MCD
#endif // LLVM_MC_MCDECODER_H
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 80d194afa926b..bb9f811683255 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -447,13 +447,13 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
#include "AMDGPUGenDisassemblerTables.inc"
+namespace {
// Define bitwidths for various types used to instantiate the decoder.
-template <> static constexpr uint32_t llvm::MCD::InsnBitWidth<uint32_t> = 32;
-template <> static constexpr uint32_t llvm::MCD::InsnBitWidth<uint64_t> = 64;
-template <>
-static constexpr uint32_t llvm::MCD::InsnBitWidth<std::bitset<96>> = 96;
-template <>
-static constexpr uint32_t llvm::MCD::InsnBitWidth<std::bitset<128>> = 128;
+template <> constexpr uint32_t InsnBitWidth<uint32_t> = 32;
+template <> constexpr uint32_t InsnBitWidth<uint64_t> = 64;
+template <> constexpr uint32_t InsnBitWidth<std::bitset<96>> = 96;
+template <> constexpr uint32_t InsnBitWidth<std::bitset<128>> = 128;
+} // namespace
//===----------------------------------------------------------------------===//
//
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 395672fe5b68b..b1b7ea5246fda 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -701,11 +701,13 @@ static constexpr DecoderListEntry DecoderList32[]{
{DecoderTableZdinxRV32Only32, {}, "RV32-only Zdinx (Double in Integer)"},
};
+namespace {
// Define bitwidths for various types used to instantiate the decoder.
-template <> constexpr uint32_t llvm::MCD::InsnBitWidth<uint16_t> = 16;
-template <> constexpr uint32_t llvm::MCD::InsnBitWidth<uint32_t> = 32;
+template <> constexpr uint32_t InsnBitWidth<uint16_t> = 16;
+template <> constexpr uint32_t InsnBitWidth<uint32_t> = 32;
// Use uint64_t to represent 48 bit instructions.
-template <> constexpr uint32_t llvm::MCD::InsnBitWidth<uint64_t> = 48;
+template <> constexpr uint32_t InsnBitWidth<uint64_t> = 48;
+} // namespace
DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
ArrayRef<uint8_t> Bytes,
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 354c2a788d5b1..6d28fa98ba9a3 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -2479,6 +2479,14 @@ void DecoderEmitter::run(raw_ostream &o) const {
#include <assert.h>
namespace {
+
+// InsnBitWidth is essentially a type trait used by the decoder emitter to query
+// the supported bitwidth for a given type. But default, the value is 0, making
+// it an invalid type for use as `InsnType` when instantiating the decoder.
+// Individual targets are expected to provide specializations for these based
+// on their usage.
+template <typename T> static constexpr uint32_t InsnBitWidth = 0;
+
)";
// Do extra bookkeeping for variable-length encodings.
|
This is confusing. Why does it warn about |
Right, the |
Note, @kazutakahirata added one more fix by making them inline, but I suspect its susceptible to the same issue. Maybe not a linker error, but since we have 2 different specializations for uint64_t with different values (64 vs 48). wrong ones being picked up potentially. In practice likely not right now, but I still feel my fix to avoid any sort of visibility of these specializations across targets through the Apologies for the churn over the long weekend :( |
@jurahul Could you rebase this PR? I think it's the right thing to hide these constants in anonymous namespaces, but I just want to build this myself. Thanks! |
4beb962
to
bbc3d88
Compare
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for rebasing this PR! I've confirmed the build is OK with this patch.
Move
InsnBitWidth
template into anonymous namespace in the generated code and move template specialization ofInsnBitWidth
to anonymous namespace as well, and dropstatic
for them. This makesInsnBitWidth
completely private to each target and fixes the "explicit specialization cannot have a storage class" warning as well as any potential linker errors ifInsnBitWidth
is kept in thellvm::MCD
namespace.