Skip to content

Commit

Permalink
[AsmParser] Report invalid data layout more gracefully
Browse files Browse the repository at this point in the history
Report this as a normal LLParser error, rather than a fatal error.
  • Loading branch information
nikic committed Jul 13, 2022
1 parent d4892a1 commit ee4d09b
Show file tree
Hide file tree
Showing 31 changed files with 40 additions and 35 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/AsmParser/LLParser.cpp
Expand Up @@ -456,10 +456,15 @@ bool LLParser::parseTargetDefinition() {
return false;
case lltok::kw_datalayout:
Lex.Lex();
if (parseToken(lltok::equal, "expected '=' after target datalayout") ||
parseStringConstant(Str))
if (parseToken(lltok::equal, "expected '=' after target datalayout"))
return true;
LocTy Loc = Lex.getLoc();
if (parseStringConstant(Str))
return true;
M->setDataLayout(Str);
Expected<DataLayout> MaybeDL = DataLayout::parse(Str);
if (!MaybeDL)
return error(Loc, toString(std::move(MaybeDL.takeError())));
M->setDataLayout(MaybeDL.get());
return false;
}
}
Expand Down
@@ -1,5 +1,5 @@
; RUN: not --crash llvm-as %s 2>&1 | FileCheck %s
; RUN: not llvm-as %s 2>&1 | FileCheck %s

; CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2
; CHECK: error: Alignment is neither 0 nor a power of 2

target datalayout = "Fi24"
@@ -1,5 +1,5 @@
; RUN: not --crash llvm-as %s 2>&1 | FileCheck %s
; RUN: not llvm-as %s 2>&1 | FileCheck %s

; CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2
; CHECK: error: Alignment is neither 0 nor a power of 2

target datalayout = "S24"
2 changes: 1 addition & 1 deletion llvm/test/Assembler/getInt.ll
@@ -1,3 +1,3 @@
; RUN: not --crash opt < %s 2>&1 | grep 'not a number, or does not fit in an unsigned int'
; RUN: not opt < %s 2>&1 | grep 'not a number, or does not fit in an unsigned int'

target datalayout = "p:4294967296:64:64"
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout-alloca-addrspace.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "A16777216"
; CHECK: Invalid address space, must be a 24-bit integer
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

; CHECK: Invalid address space, must be a 24-bit integer
target datalayout = "G16777216"
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

; CHECK: Invalid address space, must be a 24-bit integer
target datalayout = "P16777216"
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout1.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "^"
; CHECK: Unknown specifier in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout10.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m"
; CHECK: Expected mangling specifier in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout11.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m."
; CHECK: Unexpected trailing characters after mangling specifier in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout12.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "f"
; CHECK: Missing alignment specification in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout13.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = ":32"
; CHECK: Expected token before separator in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout14.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:64:16"
; CHECK: Preferred alignment cannot be less than the ABI alignment
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout15.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:16:16777216"
; CHECK: Invalid preferred alignment, must be a 16bit integer
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout16.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:16777216:16777216"
; CHECK: Invalid ABI alignment, must be a 16bit integer
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout17.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i16777216:16:16"
; CHECK: Invalid bit width, must be a 24bit integer
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout18.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:32:32:16"
; CHECK: Preferred alignment cannot be less than the ABI alignment
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout19.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "p:0:32:32"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout2.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m:v"
; CHECK: Unknown mangling in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout20.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "p:64:24:64"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout21.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "p:64:64:24"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout22.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "v128:0:128"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout23.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "i32:24:32"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout24.ll
@@ -1,4 +1,4 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "i32:32:24"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout3.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "n0"
; CHECK: Zero width native integer type in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout4.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p16777216:64:64:64"
; CHECK: Invalid address space, must be a 24bit integer
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout5.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "a1:64"
; CHECK: Sized aggregate specification in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout6.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "a:"
; CHECK: Trailing separator in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout7.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:48:52"
; CHECK: number of bits must be a byte width multiple
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout8.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "e-p"
; CHECK: Missing size specification for pointer in datalayout string
2 changes: 1 addition & 1 deletion llvm/test/Assembler/invalid-datalayout9.ll
@@ -1,3 +1,3 @@
; RUN: not --crash llvm-as < %s 2>&1 | FileCheck %s
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "e-p:64"
; CHECK: Missing alignment specification for pointer in datalayout string

1 comment on commit ee4d09b

@nunoplopes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙂

Please sign in to comment.