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

[BUG] Fatal error in clang when building with -O2 on arm64 #1207

Closed
Rakashazi opened this issue Mar 15, 2020 · 10 comments
Closed

[BUG] Fatal error in clang when building with -O2 on arm64 #1207

Rakashazi opened this issue Mar 15, 2020 · 10 comments
Assignees
Labels
Milestone

Comments

@Rakashazi
Copy link

Description

I've run into the error below when compiling a particular file with -O2 on the arm64 ABI. It doesn't happen with -O1 or -O3 on arm64, and no problems with -O2 on the same file with other ABIs. Preprocessed source and run script are also attached: bug.zip

fatal error: error in backend: Cannot select: 0x62a2a28: v4i16 = AArch64ISD::DUP 0x62ab698, ./src/vice/vicii/vicii-draw.c:1490:24 @[ ./src/vice/vicii/vicii-draw.c:1509:5 ]
0x62ab698: i16 = truncate 0x62ab700, ./src/vice/vicii/vicii-draw.c:1490:24 @[ ./src/vice/vicii/vicii-draw.c:1509:5 ]
0x62ab700: i32,ch = CopyFromReg 0x61be328, Register:i32 %7, ./src/vice/vicii/vicii-draw.c:1489:13 @[ ./src/vice/vicii/vicii-draw.c:1509:5 ]
0x62aaf48: i32 = Register %7
In function: vicii_draw_init
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)
Target: aarch64-none-linux-android21
Thread model: posix
InstalledDir: /opt/android-sdk-update-manager/ndk/21.1.6210238/toolchains/llvm/prebuilt/linux-x86_64/bin
clang: note: diagnostic msg: PLEASE submit a bug report to https://github.com/android-ndk/ndk/issues and include the crash backtrace, preprocessed source, and associated run script.

Environment Details

  • NDK Version: 21.1.6210238-beta1
  • Build system: Custom
  • Host OS: Gentoo Linux
  • ABI: arm64-v8a
  • NDK API level: 21
@Rakashazi Rakashazi added the bug label Mar 15, 2020
@Rakashazi Rakashazi changed the title [BUG] [BUG] Fatal error in clang when building with -O2 on arm64 Mar 15, 2020
@DanAlbert DanAlbert added this to the r21b milestone Mar 16, 2020
@DanAlbert
Copy link
Member

If it's quick to find the fix to cherry-pick, I think we can do this in r21b, otherwise this'll get moved to r21c.

@pirama-arumuga-nainar
Copy link
Collaborator

Reproduces with ToT as well. Get the same error as the original report. Debug build gives the following assertion:

clang++: /ssd2/pirama/llvm-monorepo/monorepo/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:978: 
void (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode *): Assertion `(TLI.ge
tTypeAction(*DAG.getContext(), Op.getValueType()) == TargetLowering::TypeLegal || Op.getOpcode()
 == ISD::TargetConstant || Op.getOpcode() == ISD::Register) && "Unexpected illegal type!"' faile
d.

@DanAlbert DanAlbert modified the milestones: r21b, r21c Mar 16, 2020
@pirama-arumuga-nainar
Copy link
Collaborator

Thanks to @gburgessiv for reducing the repro to the following. Need to test this with r20 to see if this is a regression.

clang++ -cc1 -triple aarch64-none-linux-android21 -emit-obj -O2 -vectorize-loops vicii-draw-d6b435.reduced.c

void a() {
  int c, d, b;
  char *e;
  for (;; d++)
    for (; b <= 5; b++) {
      c = 0;
      for (; c <= 15; c++) {
        e[0] = d;
        e[1] = c & 4 ?: b;
        e[2] = e[3] = c ?: b;
        e += 4;
      }
    }
}

@gburgessiv
Copy link
Collaborator

Looks like LLVM 38a0616c1df029aff481eb0224dacb55c317865e (aka r357161) is where this crash started occurring. Given that ToT is ~30K commits beyond that ATM, new sources might've been introduced in the meantime.

@stephenhines
Copy link
Collaborator

Per https://github.com/android/ndk/wiki/NDK-Release-Process, this is a Medium severity issue, so we should fix this for the next LTS toolchain update.

@DanAlbert
Copy link
Member

Yep, it's already been moved to r21c.

@stephenhines
Copy link
Collaborator

We need to get this into the LTS branch and then ship that in order to fully close this.

@stephenhines stephenhines reopened this Mar 20, 2020
@stephenhines
Copy link
Collaborator

I'll cherry-pick it to llvm-r365631.

@pirama-arumuga-nainar
Copy link
Collaborator

🤦‍♂ Thanks for noticing the auto-close.

@stephenhines
Copy link
Collaborator

arichardson pushed a commit to arichardson/llvm-project that referenced this issue Apr 2, 2020
… illegal type

Summary:
It can be the case that a vector type is legal but the corresponding
scalar type is not legal for an architecture (i8 vs. v16i8 on AArch64).
Check if the scalar type created when folding
  truncate(build_vector(x,y)) -> build_vector(truncate(x),truncate(y))

is legal if we are running after the type legalizer.

This fixes android/ndk#1207.

Reviewers: RKSimon, srhines

Subscribers: kristof.beyls, hiraditya, danielkiss, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76312
grendello added a commit to grendello/xamarin-android that referenced this issue May 29, 2020
Context: https://github.com/android/ndk/wiki/Changelog-r21#r21c

Changes:

  * [Issue 1060][0]: A macOS app bundle that is signed and notarized is now
    available for download from our wiki and our website. Note that
    because only bundles may use RPATHs and pass notarization, the
    traditional NDK package for macOS *cannot be notarized. The SDK will
    continue to use the traditional package as the app bundle requires
    layout changes that would make it incompatible with Android Studio.
    The NDK is not quarantined when it is downloaded via the SDK manager,
    so is curently allowed by Gatekeeper. The SDK manager is currently the
    most reliable way to get the NDK for macOS.
  * [Issue 1207][1]: Fix fatal error in clang when building with -O2 on arm64.
  * [Issue 1239][2]: Fix network drive issues for clang.
  * [Issue 1229][3]: README.md turned back to ordinary file.

[0]: android/ndk#1060
[1]: android/ndk#1207
[2]: android/ndk#1239
[3]: android/ndk#1229
jonpryor pushed a commit to dotnet/android that referenced this issue Jun 1, 2020
Context: https://github.com/android/ndk/wiki/Changelog-r21#r21c

Changes:

  * [Issue 1060][0]: A macOS app bundle that is signed and notarized is
    now available for download from our wiki and our website. Note that
    because only bundles may use RPATHs and pass notarization, the
    traditional NDK package for macOS *cannot* be notarized. The SDK
    will continue to use the traditional package as the app bundle
    requires layout changes that would make it incompatible with
    Android Studio.  The NDK is not quarantined when it is downloaded
    via the SDK manager, so is currently allowed by Gatekeeper. The SDK
    manager is currently the most reliable way to get the NDK for macOS.
  * [Issue 1207][1]: Fix fatal error in clang when building with -O2 on arm64.
  * [Issue 1239][2]: Fix network drive issues for clang.
  * [Issue 1229][3]: README.md turned back to ordinary file.

[0]: android/ndk#1060
[1]: android/ndk#1207
[2]: android/ndk#1239
[3]: android/ndk#1229
jonpryor pushed a commit to dotnet/android that referenced this issue Jun 1, 2020
Context: https://github.com/android/ndk/wiki/Changelog-r21#r21c

Changes:

  * [Issue 1060][0]: A macOS app bundle that is signed and notarized is
    now available for download from our wiki and our website. Note that
    because only bundles may use RPATHs and pass notarization, the
    traditional NDK package for macOS *cannot* be notarized. The SDK
    will continue to use the traditional package as the app bundle
    requires layout changes that would make it incompatible with
    Android Studio.  The NDK is not quarantined when it is downloaded
    via the SDK manager, so is currently allowed by Gatekeeper. The SDK
    manager is currently the most reliable way to get the NDK for macOS.
  * [Issue 1207][1]: Fix fatal error in clang when building with -O2 on arm64.
  * [Issue 1239][2]: Fix network drive issues for clang.
  * [Issue 1229][3]: README.md turned back to ordinary file.

[0]: android/ndk#1060
[1]: android/ndk#1207
[2]: android/ndk#1239
[3]: android/ndk#1229
wantguns pushed a commit to wantguns/toolchain_llvm_android that referenced this issue Jul 17, 2020
Bug: android/ndk#1207.

This issue is present since r357161 (38a0616c1).

Change-Id: I5f200ba01764828a31eb3e51f00bca29fda865e5
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
… illegal type

Summary:
It can be the case that a vector type is legal but the corresponding
scalar type is not legal for an architecture (i8 vs. v16i8 on AArch64).
Check if the scalar type created when folding
  truncate(build_vector(x,y)) -> build_vector(truncate(x),truncate(y))

is legal if we are running after the type legalizer.

This fixes android/ndk#1207.

Reviewers: RKSimon, srhines

Subscribers: kristof.beyls, hiraditya, danielkiss, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants