[PATCH] D43317: [WebAssebmly] Remove use of Optional to fix assertion in gcc
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 14:44:06 PST 2018
sbc100 updated this revision to Diff 134319.
sbc100 added a comment.
- feedback
- Revert "Remove a failing static_assert."
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D43317
Files:
wasm/Symbols.cpp
wasm/Symbols.h
Index: wasm/Symbols.h
===================================================================
--- wasm/Symbols.h
+++ wasm/Symbols.h
@@ -23,6 +23,8 @@
class InputFile;
class InputChunk;
+#define INVALID_INDEX UINT32_MAX
+
// The base class for real symbol classes.
class Symbol {
public:
@@ -82,7 +84,7 @@
uint32_t Flags;
InputFile *File;
InputChunk *Chunk;
- llvm::Optional<uint32_t> OutputIndex;
+ uint32_t OutputIndex = INVALID_INDEX;
};
class FunctionSymbol : public Symbol {
@@ -110,7 +112,7 @@
InputChunk *C)
: Symbol(Name, K, Flags, F, C) {}
- llvm::Optional<uint32_t> TableIndex;
+ uint32_t TableIndex = INVALID_INDEX;
// Explict function type, needed for undefined or synthetic functions only.
const WasmSignature *FunctionType = nullptr;
@@ -237,6 +239,8 @@
template <typename T, typename... ArgT>
T *replaceSymbol(Symbol *S, ArgT &&... Arg) {
+ static_assert(std::is_trivially_destructible<T>(),
+ "Symbol types must be trivially destructible");
static_assert(sizeof(T) <= sizeof(SymbolUnion), "Symbol too small");
static_assert(alignof(T) <= alignof(SymbolUnion),
"SymbolUnion not aligned enough");
Index: wasm/Symbols.cpp
===================================================================
--- wasm/Symbols.cpp
+++ wasm/Symbols.cpp
@@ -31,19 +31,20 @@
bool Symbol::hasOutputIndex() const {
if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
return F->hasOutputIndex();
- return OutputIndex.hasValue();
+ return OutputIndex != INVALID_INDEX;
}
uint32_t Symbol::getOutputIndex() const {
if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
return F->getOutputIndex();
- return OutputIndex.getValue();
+ assert(OutputIndex != INVALID_INDEX);
+ return OutputIndex;
}
void Symbol::setOutputIndex(uint32_t Index) {
DEBUG(dbgs() << "setOutputIndex " << Name << " -> " << Index << "\n");
assert(!dyn_cast_or_null<InputFunction>(Chunk));
- assert(!OutputIndex.hasValue());
+ assert(OutputIndex == INVALID_INDEX);
OutputIndex = Index;
}
@@ -85,13 +86,14 @@
uint32_t FunctionSymbol::getTableIndex() const {
if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
return F->getTableIndex();
- return TableIndex.getValue();
+ assert(TableIndex != INVALID_INDEX);
+ return TableIndex;
}
bool FunctionSymbol::hasTableIndex() const {
if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
return F->hasTableIndex();
- return TableIndex.hasValue();
+ return TableIndex != INVALID_INDEX;
}
void FunctionSymbol::setTableIndex(uint32_t Index) {
@@ -103,7 +105,7 @@
return;
}
DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n");
- assert(!TableIndex.hasValue());
+ assert(TableIndex == INVALID_INDEX);
TableIndex = Index;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43317.134319.patch
Type: text/x-patch
Size: 2824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180214/7c36a769/attachment.bin>
More information about the llvm-commits
mailing list