Skip to content

Commit

Permalink
[WebAssebmly] Remove use of Optional to fix assertion in gcc
Browse files Browse the repository at this point in the history
This was causing GCC builds with fail with:
Symbols.h:240:3: error: static assertion failed: Symbol types must be
trivially destructible
  static_assert(std::is_trivially_destructible<T>(

The reason this is a gcc-only failure is that OptionalStorage has
as specialization for POD types that isn't built under GCC.

Differential Revision: https://reviews.llvm.org/D43317

llvm-svn: 325185
  • Loading branch information
sbc100 committed Feb 14, 2018
1 parent 0465e2a commit c484ee0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lld/wasm/Symbols.cpp
Expand Up @@ -31,19 +31,20 @@ DefinedGlobal *WasmSym::StackPointer;
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;
}

Expand Down Expand Up @@ -85,13 +86,14 @@ void FunctionSymbol::setFunctionType(const WasmSignature *Type) {
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) {
Expand All @@ -103,7 +105,7 @@ void FunctionSymbol::setTableIndex(uint32_t Index) {
return;
}
DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n");
assert(!TableIndex.hasValue());
assert(TableIndex == INVALID_INDEX);
TableIndex = Index;
}

Expand Down
8 changes: 6 additions & 2 deletions lld/wasm/Symbols.h
Expand Up @@ -23,6 +23,8 @@ namespace wasm {
class InputFile;
class InputChunk;

#define INVALID_INDEX UINT32_MAX

// The base class for real symbol classes.
class Symbol {
public:
Expand Down Expand Up @@ -82,7 +84,7 @@ class Symbol {
uint32_t Flags;
InputFile *File;
InputChunk *Chunk;
llvm::Optional<uint32_t> OutputIndex;
uint32_t OutputIndex = INVALID_INDEX;
};

class FunctionSymbol : public Symbol {
Expand Down Expand Up @@ -110,7 +112,7 @@ class FunctionSymbol : public Symbol {
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;
Expand Down Expand Up @@ -237,6 +239,8 @@ union SymbolUnion {

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");
Expand Down

0 comments on commit c484ee0

Please sign in to comment.