mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Fix non-global-value-max-name-size not considered by LLParser
`non-global-value-max-name-size` is used by `Value` to cap the length of local value name. However, this flag is not considered by `LLParser`, which leads to unexpected `use of undefined value error`. The fix is to move the responsibility of capping the length to `ValueSymbolTable`. The test is the one provided by [[ https://bugs.llvm.org/show_bug.cgi?id=45899 | Mikael in the bug report ]]. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D102707
This commit is contained in:
parent
0a4cf978a7
commit
aa98e6ea8a
@ -60,18 +60,23 @@ public:
|
||||
/// @name Constructors
|
||||
/// @{
|
||||
|
||||
ValueSymbolTable() : vmap(0) {}
|
||||
ValueSymbolTable(int MaxNameSize = -1) : vmap(0), MaxNameSize(MaxNameSize) {}
|
||||
~ValueSymbolTable();
|
||||
|
||||
/// @}
|
||||
/// @name Accessors
|
||||
/// @{
|
||||
/// @}
|
||||
/// @name Accessors
|
||||
/// @{
|
||||
|
||||
/// This method finds the value with the given \p Name in the
|
||||
/// the symbol table.
|
||||
/// @returns the value associated with the \p Name
|
||||
/// Lookup a named Value.
|
||||
Value *lookup(StringRef Name) const { return vmap.lookup(Name); }
|
||||
Value *lookup(StringRef Name) const {
|
||||
if (MaxNameSize > -1 && Name.size() > (unsigned)MaxNameSize)
|
||||
Name = Name.substr(0, std::max(1u, (unsigned)MaxNameSize));
|
||||
|
||||
return vmap.lookup(Name);
|
||||
}
|
||||
|
||||
/// @returns true iff the symbol table is empty
|
||||
/// Determine if the symbol table is empty
|
||||
@ -128,6 +133,8 @@ private:
|
||||
/// @{
|
||||
|
||||
ValueMap vmap; ///< The map that holds the symbol table.
|
||||
int MaxNameSize; ///< The maximum size for each name. If the limit is
|
||||
///< exceeded, the name is capped.
|
||||
mutable uint32_t LastUnique = 0; ///< Counter for tracking unique names
|
||||
|
||||
/// @}
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "llvm/IR/ValueSymbolTable.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include <algorithm>
|
||||
@ -76,6 +77,10 @@ using ProfileCount = Function::ProfileCount;
|
||||
// are not in the public header file...
|
||||
template class llvm::SymbolTableListTraits<BasicBlock>;
|
||||
|
||||
static cl::opt<unsigned> NonGlobalValueMaxNameSize(
|
||||
"non-global-value-max-name-size", cl::Hidden, cl::init(1024),
|
||||
cl::desc("Maximum size for the name of non-global values."));
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Argument Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
@ -391,7 +396,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
|
||||
|
||||
// We only need a symbol table for a function if the context keeps value names
|
||||
if (!getContext().shouldDiscardValueNames())
|
||||
SymTab = std::make_unique<ValueSymbolTable>();
|
||||
SymTab = std::make_unique<ValueSymbolTable>(NonGlobalValueMaxNameSize);
|
||||
|
||||
// If the function has arguments, mark them as lazily built.
|
||||
if (Ty->getNumParams())
|
||||
|
@ -72,7 +72,7 @@ template class llvm::SymbolTableListTraits<GlobalIFunc>;
|
||||
//
|
||||
|
||||
Module::Module(StringRef MID, LLVMContext &C)
|
||||
: Context(C), ValSymTab(std::make_unique<ValueSymbolTable>()),
|
||||
: Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)),
|
||||
Materializer(), ModuleID(std::string(MID)),
|
||||
SourceFileName(std::string(MID)), DL("") {
|
||||
Context.addModule(this);
|
||||
|
@ -42,11 +42,6 @@ static cl::opt<unsigned> UseDerefAtPointSemantics(
|
||||
"use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false),
|
||||
cl::desc("Deref attributes and metadata infer facts at definition only"));
|
||||
|
||||
|
||||
static cl::opt<unsigned> NonGlobalValueMaxNameSize(
|
||||
"non-global-value-max-name-size", cl::Hidden, cl::init(1024),
|
||||
cl::desc("Maximum size for the name of non-global values."));
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Value Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
@ -323,11 +318,6 @@ void Value::setNameImpl(const Twine &NewName) {
|
||||
if (getName() == NameRef)
|
||||
return;
|
||||
|
||||
// Cap the size of non-GlobalValue names.
|
||||
if (NameRef.size() > NonGlobalValueMaxNameSize && !isa<GlobalValue>(this))
|
||||
NameRef =
|
||||
NameRef.substr(0, std::max(1u, (unsigned)NonGlobalValueMaxNameSize));
|
||||
|
||||
assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
|
||||
|
||||
// Get the symbol table to update for this object.
|
||||
|
@ -100,6 +100,9 @@ void ValueSymbolTable::removeValueName(ValueName *V) {
|
||||
/// it into the symbol table with the specified name. If it conflicts, it
|
||||
/// auto-renames the name and returns that instead.
|
||||
ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
|
||||
if (MaxNameSize > -1 && Name.size() > (unsigned)MaxNameSize)
|
||||
Name = Name.substr(0, std::max(1u, (unsigned)MaxNameSize));
|
||||
|
||||
// In the common case, the name is not already in the symbol table.
|
||||
auto IterBool = vmap.insert(std::make_pair(Name, V));
|
||||
if (IterBool.second) {
|
||||
|
10
test/Assembler/non-global-value-max-name-size.ll
Normal file
10
test/Assembler/non-global-value-max-name-size.ll
Normal file
@ -0,0 +1,10 @@
|
||||
; RUN: opt < %s -S -non-global-value-max-name-size=4
|
||||
; Test that local value name lookup works if the name is capped
|
||||
|
||||
define void @f() {
|
||||
bb0:
|
||||
br label %testz
|
||||
|
||||
testz:
|
||||
br label %testz
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user