Skip to content

Fix Unit tests under LLVM 11 #227

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

Merged
merged 7 commits into from
Feb 18, 2021

Conversation

matthewseaman
Copy link
Collaborator

@matthewseaman matthewseaman commented Feb 16, 2021

Resolves #225.

Two issues needed addressed.

Argument Auto-Generated Names

Per LLVM 10.0 release notes:

Unnamed function arguments now get printed with their automatically generated name (e.g. “i32 %0”) in definitions. This may require front-ends to update their tests; if so there is a script utils/add_argument_names.py that correctly converted 80-90% of Clang tests. Some manual work will almost certainly still be needed.

For example, IR that used to be:

define i32 @fn(i32 zeroext, i8* align 8)

becomes:

define i32 @fn(i32 zeroext %0, i8* align 8 %1)

Solution: Update file check statements to include argument names.

Default Alignments

Couldn't find it mentioned in the release notes, but a recent LLVM seems to have changed the spec for alloca, load, and store such that align is now required to be specified in the IR with the alignment value. (See here.) Functions such as LLVMBuildAlloca will now auto-generate an alignment, although one can be explicitly specified via LLVMSetAlignment.

Unfortunately, with this change, calling LLVMSetAlignment with an alignment of 0 is unsupported (this could be a bug in LLVM). When 0 is passed, internally LLVM now wraps it in an Align rather than a MaybeAlign and does not perform a 0 check (see here.). Eventually, Log2 is called on the alignment, and the shortcut for Log2 (e.g. 31 - leading zero bit count) results in an overflow of the unsigned integer. This causes a very large alignment value and module verification fails.

Solution: Keep the generated alignment value from methods like LLVMBuildAlloca and only explicit set one when non-zero.

Per LLVM 10.0 release notes:
"Unnamed function arguments now get printed with their automatically generated name (e.g. “i32 %0”) in definitions. This may require front-ends to update their tests; if so there is a script utils/add_argument_names.py that correctly converted 80-90% of Clang tests. Some manual work will almost certainly still be needed."
A recent version of LLVM removed implicit alignments from alloca, load, and store. This means that an "align n" must be present on those instructions, although one will be automatically generated by LLVMBuildAlloca and similar instructions. As part of this, LLVM changed the behavior of LLVMSetAlignment to wrap the alignment in an Align rather than a MaybeAlign. As a result, when an alignment 0 is explicitly set, LLVM assumes it is greater than 0 and takes the log2 of it. The shortcut algorithm for log2 (e.g. 31 - leading zero bit count) results in an overflow when the alignment is 0. This causes the module verifier to fail.

Solution: Let the default alignment be calculated and don't explicitly set it when no explicit alignment is specified.
@matthewseaman
Copy link
Collaborator Author

Still doing an audit of alignment usage.

Guard against 0 and correct 64-bit log2 for 32-bit input
Putting 0 alignments in here goes against DWARF
@matthewseaman matthewseaman merged commit f2caa21 into llvm-swift:master Feb 18, 2021
@matthewseaman matthewseaman deleted the llvm-11-tests branch February 18, 2021 02:35
matthewseaman added a commit that referenced this pull request Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit Tests Failures
2 participants