Skip to content

Commit

Permalink
Revert "[OpaquePtr][LLParser] Automatically detect opaque pointers in…
Browse files Browse the repository at this point in the history
… .ll files"

This reverts commit 295172e.

Reason: Broke the ASan buildbot. More details are available on the
original Phab review at https://reviews.llvm.org/D119482.
  • Loading branch information
hctim committed Mar 21, 2022
1 parent a80c6c7 commit 9c96a6b
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 62 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/AsmParser/LLLexer.h
Expand Up @@ -37,7 +37,7 @@ namespace llvm {
lltok::Kind CurKind;
std::string StrVal;
unsigned UIntVal;
Type *TyVal = nullptr;
Type *TyVal;
APFloat APFloatVal;
APSInt APSIntVal;

Expand Down
7 changes: 2 additions & 5 deletions llvm/include/llvm/AsmParser/LLParser.h
Expand Up @@ -95,8 +95,6 @@ namespace llvm {
typedef LLLexer::LocTy LocTy;
private:
LLVMContext &Context;
// Lexer to determine whether to use opaque pointers or not.
LLLexer OPLex;
LLLexer Lex;
// Module being parsed, null if we are only parsing summary index.
Module *M;
Expand Down Expand Up @@ -159,9 +157,8 @@ namespace llvm {
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M,
ModuleSummaryIndex *Index, LLVMContext &Context,
SlotMapping *Slots = nullptr)
: Context(Context), OPLex(F, SM, Err, Context),
Lex(F, SM, Err, Context), M(M), Index(Index), Slots(Slots),
BlockAddressPFS(nullptr) {}
: Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index),
Slots(Slots), BlockAddressPFS(nullptr) {}
bool Run(
bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback =
[](StringRef) { return None; });
Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/IR/LLVMContext.h
Expand Up @@ -305,9 +305,6 @@ class LLVMContext {
/// LLVMContext is used by compilation.
void setOptPassGate(OptPassGate&);

/// Whether we've decided on using opaque pointers or typed pointers yet.
bool hasSetOpaquePointersValue() const;

/// Enable opaque pointers. Can only be called before creating the first
/// pointer type.
void enableOpaquePointers() const;
Expand Down
5 changes: 1 addition & 4 deletions llvm/lib/AsmParser/LLLexer.cpp
Expand Up @@ -860,10 +860,7 @@ lltok::Kind LLLexer::LexIdentifier() {
TYPEKEYWORD("token", Type::getTokenTy(Context));

if (Keyword == "ptr") {
// enableOpaquePointers() must be called before creating any pointer types.
if (!Context.hasSetOpaquePointersValue()) {
Context.enableOpaquePointers();
} else if (Context.supportsTypedPointers()) {
if (Context.supportsTypedPointers()) {
Warning("ptr type is only supported in -opaque-pointers mode");
return lltok::Error;
}
Expand Down
20 changes: 0 additions & 20 deletions llvm/lib/AsmParser/LLParser.cpp
Expand Up @@ -59,29 +59,9 @@ static std::string getTypeString(Type *T) {
return Tmp.str();
}

static void setContextOpaquePointers(LLLexer &L, LLVMContext &C) {
while (true) {
lltok::Kind K = L.Lex();
// LLLexer will set the opaque pointers option in LLVMContext if it sees an
// explicit "ptr".
if (K == lltok::star || K == lltok::Error || K == lltok::Eof ||
isa_and_nonnull<PointerType>(L.getTyVal())) {
return;
}
}
}

/// Run: module ::= toplevelentity*
bool LLParser::Run(bool UpgradeDebugInfo,
DataLayoutCallbackTy DataLayoutCallback) {
// If we haven't decided on whether or not we're using opaque pointers, do a
// quick lex over the tokens to see if we explicitly construct any typed or
// opaque pointer types.
// Don't bail out on an error so we do the same work in the parsing below
// regardless of if --opaque-pointers is set.
if (!Context.hasSetOpaquePointersValue())
setContextOpaquePointers(OPLex, Context);

// Prime the lexer.
Lex.Lex();

Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/IR/LLVMContext.cpp
Expand Up @@ -351,10 +351,6 @@ std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
return std::move(pImpl->DiagHandler);
}

bool LLVMContext::hasSetOpaquePointersValue() const {
return pImpl->hasOpaquePointersValue();
}

void LLVMContext::enableOpaquePointers() const {
assert(pImpl->PointerTypes.empty() && pImpl->ASPointerTypes.empty() &&
"Must be called before creating any pointer types");
Expand Down
12 changes: 2 additions & 10 deletions llvm/lib/IR/LLVMContextImpl.cpp
Expand Up @@ -47,11 +47,7 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
X86_FP80Ty(C, Type::X86_FP80TyID), FP128Ty(C, Type::FP128TyID),
PPC_FP128Ty(C, Type::PPC_FP128TyID), X86_MMXTy(C, Type::X86_MMXTyID),
X86_AMXTy(C, Type::X86_AMXTyID), Int1Ty(C, 1), Int8Ty(C, 8),
Int16Ty(C, 16), Int32Ty(C, 32), Int64Ty(C, 64), Int128Ty(C, 128) {
if (OpaquePointersCL.getNumOccurrences()) {
OpaquePointers = OpaquePointersCL;
}
}
Int16Ty(C, 16), Int32Ty(C, 32), Int64Ty(C, 64), Int128Ty(C, 128) {}

LLVMContextImpl::~LLVMContextImpl() {
// NOTE: We need to delete the contents of OwnedModules, but Module's dtor
Expand Down Expand Up @@ -249,13 +245,9 @@ void LLVMContextImpl::setOptPassGate(OptPassGate& OPG) {
this->OPG = &OPG;
}

bool LLVMContextImpl::hasOpaquePointersValue() {
return OpaquePointers.hasValue();
}

bool LLVMContextImpl::getOpaquePointers() {
if (LLVM_UNLIKELY(!(OpaquePointers.hasValue())))
OpaquePointers = false;
OpaquePointers = OpaquePointersCL;
return *OpaquePointers;
}

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/IR/LLVMContextImpl.h
Expand Up @@ -1555,7 +1555,6 @@ class LLVMContextImpl {
// TODO: clean up the following after we no longer support non-opaque pointer
// types.
bool getOpaquePointers();
bool hasOpaquePointersValue();
void setOpaquePointers(bool OP);

private:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/ptr-outside-opaque-pointers-mode.ll
@@ -1,4 +1,4 @@
; RUN: not llvm-as < %s -disable-output --opaque-pointers=0 2>&1 | FileCheck %s
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s

; CHECK: warning: ptr type is only supported in -opaque-pointers mode
; CHECK: error: expected type
Expand Down
@@ -1,4 +1,4 @@
; RUN: llvm-as --opaque-pointers < %s | not llvm-dis --opaque-pointers=0 2>&1 | FileCheck %s
; RUN: llvm-as --opaque-pointers < %s | not llvm-dis 2>&1 | FileCheck %s

; CHECK: error: Opaque pointers are only supported in -opaque-pointers mode

Expand Down
6 changes: 0 additions & 6 deletions llvm/test/Other/mixed-opaque-ptrs-2.ll

This file was deleted.

6 changes: 0 additions & 6 deletions llvm/test/Other/mixed-opaque-ptrs.ll

This file was deleted.

0 comments on commit 9c96a6b

Please sign in to comment.