Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update test cases to LLVM 9.0 #105

Closed
mewmew opened this issue Oct 31, 2019 · 10 comments
Closed

update test cases to LLVM 9.0 #105

mewmew opened this issue Oct 31, 2019 · 10 comments

Comments

@mewmew
Copy link
Member

mewmew commented Oct 31, 2019

Some of the previously valid test cases (taken from the 7.0 release of LLVM) are no longer valid.

Error reported by opt of the LLVM 9.0 release when parsing testdata/llvm/test/Analysis/DominanceFrontier/new_pm_test.ll:

$ opt -S -o foo.ll new_pm_test.ll
opt: new_pm_test.ll:29:1: error: label expected to be numbered '12'
13:
^

Error reported by go test for llir/llvm once updated to handle explicitly named unnamed basic blocks (as done in LLVM 9.0); see #104.

From https://travis-ci.org/llir/llvm/jobs/605020808#L708:

--- FAIL: TestParseFile (40.39s)

    asm_test.go:533: unable to parse "../testdata/llvm/test/Analysis/DominanceFrontier/new_pm_test.ll" into AST;
    invalid local ID in function "@a_linear_impl_fig_1", expected %12, got %13
@mewmew

This comment has been minimized.

mewmew added a commit to llir/testdata that referenced this issue Oct 31, 2019
Note, we still have to update golden test cases,
that is the expected output of llir/llvm (since
comments are ignored and whitespace may differ).

Updates llir/llvm#105.
@mewmew
Copy link
Member Author

mewmew commented Nov 1, 2019

Note, to update the test cases from LLVM 7.0 to LLVM 9.0, the following steps were taken.

Update VER in testdata/llvm/Makefile:

 # LLVM version.
-VER=7.0.0
+VER=9.0.0

Run make to download the LLVM 9.0 source release and extract *.ll test cases from it.

From the testdata/llvm directory of the testdata repository.

make

Run skip.sh to skip a few "bad" test cases.

./skip.sh

Commit new test cases to the Git repo.

git add llvm/test
git commit -m 'llvm: update test cases to LLVM 9.0 release'

The remaining step is to update the testdata submodule of the llir/llvm repository, and then run go test github.com/llir/llvm/... to see if any of the golden output changed.

Each test case (e.g. llvm/test/Analysis/DominanceFrontier/new_pm_test.ll) has a corresponding golden output (e.g. llvm/test/Analysis/DominanceFrontier/new_pm_test.ll.golden), since the input may differ from the expected output (in the golden output comments are removed and whitespace may change as compared to the input).

Sometimes the expected output changes when the grammar of LLVM IR is updated in between LLVM releases. Otherwise the expected output should remain stable.

Once the test cases are commited, we enter an iterative process of updating the LLVM IR grammar to incorporate new changes made to the LLVM IR language as part of the release, and then if new concepts are added to the language, then add the respective concepts to llir/llvm/ir. For the LLVM 9.0 release, this corresponds to the tracking issue #101.

mewmew added a commit to llir/testdata that referenced this issue Nov 1, 2019
mewmew added a commit to llir/testdata that referenced this issue Nov 1, 2019
Add `partition` language concept.

Updates llir/llvm#105.
mewmew added a commit to llir/testdata that referenced this issue Nov 1, 2019
@mewmew mewmew mentioned this issue Nov 27, 2019
16 tasks
@mewmew mewmew added this to the v0.3 milestone Nov 27, 2019
mewmew added a commit that referenced this issue Nov 27, 2019
mewmew added a commit to llir/testdata that referenced this issue Nov 27, 2019
@mewmew
Copy link
Member Author

mewmew commented Nov 27, 2019

The only test case currently failing is testdata/llvm/test/Assembler/diexpression.ll (syntax error at line 24), because the parser generated from the [ll.tm](!7 = !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_signed)) grammar fails to parse this line:

!7 = !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_signed)

Results from go test ./...

--- FAIL: TestParseFile (34.42s)
    asm_test.go:533: unable to parse "../testdata/llvm/test/Assembler/diexpression.ll" into AST; syntax error at line 24
        unable to parse "../testdata/llvm/test/Assembler/diexpression.ll" into an AST
        github.com/llir/llvm/asm.ParseString
        	/home/u/Desktop/go/src/github.com/llir/llvm/asm/asm.go:58
        github.com/llir/llvm/asm.ParseBytes
        	/home/u/Desktop/go/src/github.com/llir/llvm/asm/asm.go:48
        github.com/llir/llvm/asm.ParseFile
        	/home/u/Desktop/go/src/github.com/llir/llvm/asm/asm.go:29
        github.com/llir/llvm/asm.TestParseFile
        	/home/u/Desktop/go/src/github.com/llir/llvm/asm/asm_test.go:531
        testing.tRunner
        	/home/u/go/src/testing/testing.go:954
        runtime.goexit
        	/home/u/go/src/runtime/asm_amd64.s:1375

@mewmew
Copy link
Member Author

mewmew commented Nov 27, 2019

@dannypsnl, feel like taking a look at adding the enums needed to help the parser handle this line? (I think it is DW_OP_LLVM_xxx)

!7 = !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_signed)

@dannypsnl
Copy link
Member

dannypsnl commented Nov 27, 2019

I dig into this case, the parser returns error: unable to locate DwarfOp enum corresponding to "DW_OP_LLVM_convert", but it seems like there was a rule for it?

https://github.com/llir/grammar/blob/f1eb80e86b542bd8a463371e8a99e116c61d2364/ll.tm#L107

Update

I think I got the point, but how to generate enum?

@dannypsnl
Copy link
Member

dannypsnl commented Nov 27, 2019

By the way, would you like to use official IR Parser by submodule LLVM-IR-parser and mapping ast only? textmapper didn't provide a reasonable result for parsing error. I didn't know which step it stuck.

All I got was: syntax error at line 1

Here is the test code:

package asm

import (
	"testing"

	"github.com/llir/ll/ast"
)

func TestParse(t *testing.T) {
	testCode := `!7 = !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_signed)`
	_, err := ast.Parse("", testCode)
	if err != nil {
		t.Error(err)
	}
}

@mewmew
Copy link
Member Author

mewmew commented Nov 27, 2019

Hi @dannypsnl!

Great that you started working on this!

The test case you wrote is good. Unfortunately Textmapper does not show column, but only line offset of errors. I'll submit an issue upstream.

One thing you could do for now to get more useful errors is to split the line into multiple lines (since whitespace tokens are ignored):

!7
=
!DIExpression(DW_OP_LLVM_convert,
16,
DW_ATE_unsigned,
DW_OP_LLVM_convert,
32,
DW_ATE_signed
)

Now, we get the error at "line 5".

$ go test -v
=== RUN   TestParse
    TestParse: aaa_test.go:18: syntax error at line 5

Which corresponds to this line:

DW_ATE_unsigned,

So, we now know it fails to parse Dwarf Attribute Encodings in DIExpressions. Lets look at the update to the C++ parser in LLVM 9.0 to see what changed.

An update was made to ParseDIExpression in LLVM 9.0. It now includes DwarfAttEncoding as a valid field. Previously only DwarfOp and Int were valid.

To see the diff, run:

diff -u llvm-7.0.0.src/lib/AsmParser/ llvm-9.0.0.src/lib/AsmParser/

The relevant part for this change is in lib/AsmParser/LLParser.cpp, more specifically in LLParser::ParseDIExpression, where the following code was added:

+      if (Lex.getKind() == lltok::DwarfAttEncoding) {
+        if (unsigned Op = dwarf::getAttributeEncoding(Lex.getStrVal())) {
+          Lex.Lex();
+          Elements.push_back(Op);
+          continue;
+        }
+        return TokError(Twine("invalid DWARF attribute encoding '") + Lex.getStrVal() + "'");
+      }
+

So, the ll.tm grammar has to be updated accordingly.

From:

DIExpressionField -> DIExpressionField
	: UintLit
	| DwarfOp
;

To:

DIExpressionField -> DIExpressionField
	: UintLit
	| DwarfAttEncoding
	| DwarfOp
;

mewmew added a commit to llir/grammar that referenced this issue Nov 27, 2019
@mewmew
Copy link
Member Author

mewmew commented Nov 27, 2019

The grammar has now been updated llir/grammar@7cadd4c

Edit: so now the test case you provided works, the input LLVM IR is successfully parsed into its AST representation:

$ go test -v
=== RUN   TestParse
--- PASS: TestParse (0.00s)

mewmew added a commit to llir/testdata that referenced this issue Nov 27, 2019
This includes the DW_OP_LLVM_convert and DW_OP_LLVM_tag_offset enums
of LLVM 9.0, and the use of Dwarf Attribute Encoding in DIExpression
(e.g. DW_ATE_unsigned).

Updates llir/llvm#105.
mewmew pushed a commit that referenced this issue Nov 28, 2019
* (#105) add enum: DW_OP_LLVM_convert

```
go generate ./...
cd asm/enum && make
```

issue: still can't fix the bug #105 (comment)

* (#105) add enums

DW_OP_LLVM_tag_offset = 0x1002
DW_OP_GNU_entry_value = 0xf3

* (#105) fix goimports version to correct imports
@mewmew
Copy link
Member Author

mewmew commented Nov 28, 2019

Fixed by @dannypsnl in #110.

@mewmew
Copy link
Member Author

mewmew commented Dec 4, 2019

The test case you wrote is good. Unfortunately Textmapper does not show column, but only line offset of errors. I'll submit an issue upstream.

Reported upstream at inspirer/textmapper#36

mewmew added a commit to llir/testdata that referenced this issue Nov 8, 2020
This was done by following the steps outlined in #132 and
llir/llvm#105 (comment)
mewmew added a commit to llir/testdata that referenced this issue Mar 24, 2021
* llvm: update test cases to LLVM 11.0 release

This was done by following the steps outlined in #132 and
llir/llvm#105 (comment)

* llvm: update golden test cases to LLVM 11.0

Updates llir/llvm#158.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants