-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver] Don't alias -mstrict-align to -mno-unaligned-access #85350
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
MaskRay
merged 5 commits into
main
from
users/MaskRay/spr/driver-dont-alias-mstrict-align-to-mno-unaligned-access
Mar 15, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,35 @@ | ||
/// Test -m[no-]unaligned-access and -m[no-]strict-align options. | ||
|
||
// RUN: %clang --target=loongarch64 -munaligned-access -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-unaligned-access -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mstrict-align -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-strict-align -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -munaligned-access -mno-unaligned-access -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-unaligned-access -munaligned-access -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mstrict-align -mno-strict-align -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-strict-align -mstrict-align -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -munaligned-access -mstrict-align -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mstrict-align -munaligned-access -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-unaligned-access -mno-strict-align -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-strict-align -mno-unaligned-access -fsyntax-only %s -### 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED | ||
|
||
// RUN: %clang --target=loongarch64 -munaligned-access -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-unaligned-access -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mstrict-align -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-strict-align -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -munaligned-access -mno-unaligned-access -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-unaligned-access -munaligned-access -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mstrict-align -mno-strict-align -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-strict-align -mstrict-align -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -munaligned-access -mstrict-align -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mstrict-align -munaligned-access -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-unaligned-access -mno-strict-align -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED | ||
// RUN: %clang --target=loongarch64 -mno-strict-align -mno-unaligned-access -S -emit-llvm %s -o - | \ | ||
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED | ||
|
||
// RUN: not %clang -### --target=loongarch64 -mno-unaligned-access -munaligned-access %s 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefix=ERR | ||
|
||
// CC1-UNALIGNED: "-target-feature" "+ual" | ||
// CC1-NO-UNALIGNED: "-target-feature" "-ual" | ||
|
||
// IR-UNALIGNED: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+ual{{(,.*)?}}" | ||
// IR-NO-UNALIGNED: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-ual{{(,.*)?}}" | ||
|
||
// ERR: error: unsupported option '-mno-unaligned-access' for target 'loongarch64' | ||
// ERR: error: unsupported option '-munaligned-access' for target 'loongarch64' | ||
|
||
int foo(void) { | ||
return 3; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
/// Check -m[no-]unaligned-access and -m[no-]strict-align are warned unused on a target that does not support them. | ||
/// Check -m[no-]unaligned-access and -m[no-]strict-align are errored on a target that does not support them. | ||
|
||
// RUN: not %clang --target=x86_64 -munaligned-access -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=unaligned-access | ||
// RUN: not %clang --target=x86_64 -mno-unaligned-access -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=no-unaligned-access | ||
// RUN: not %clang --target=x86_64 -mstrict-align -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=strict-align | ||
// RUN: not %clang --target=x86_64 -mno-strict-align -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=no-strict-align | ||
// RUN: not %clang --target=x86_64 -mno-strict-align -mstrict-align -fsyntax-only %s -### 2>&1 | FileCheck %s --check-prefix=ALIGN | ||
|
||
// CHECK: error: unsupported option '-m{{(no-)?}}unaligned-access' for target '{{.*}}' | ||
// ALIGN: error: unsupported option '-mno-strict-align' for target '{{.*}}' | ||
// ALIGN: error: unsupported option '-mstrict-align' for target '{{.*}}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep
mno_unaligned_access
for AArch64 while remove it from RISC-V and LoongArch?In fact
mno_unaligned_access
is not supported by GCC for AArch64?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For MIPSr6, since
mno_unaligned_access
has been in GCC for almost 2 years, I prefer support these 2 options both for LLVM and GCC.In fact, I don't think that it is a bad idea to support these 2 options both: it will make life easier for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we prefer strict-align, we may claim
mno_unaligned_access
as obsolete in our documents.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AArch64 supports Apple OSes. I am unclear whether have any unintended
-munaligned-access
/-mno-unaligned-access
. I'd like to remove them as well, but probably later.For RISC-V and LoongArch, they have Linux support and the GCC influence is very strong. The Clang support is also relatively new. Removing the alias likely cause no disruption at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I will add
strict_align
for MIPSr6 to GCC, and rebase my PR to LLVM.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. When you implement -munaligned-access for LLVM's MIPS port, be sure to update the HelpText in
clang/include/clang/Driver/Options.td
AArch32/MIPS only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preventing unaligned access can be useful in AArch64, it is an option we do use to build our embedded C-libraries with (not a focus for GCC). It is documented in the toolchain manual https://developer.arm.com/documentation/101754/0621/armclang-Reference/armclang-Command-line-Options/-munaligned-access---mno-unaligned-access
In summary, we'd like to keep it for AArch64.
AArch64 always has the option of using unaligned accesses, but they can be disabled by writing the SCTLR register, and accesses to Device memory always need to be aligned. Code that runs before the MMU is enabled runs as if Device memory.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the AArch64 notes.
This HelpText (
AArch32 only
) change is to discourage-munaligned-access
for AArch64, since GCC doesn't support-munaligned-access
.Personally I assume that most modern architectures should switch to
-mstrict-align
, if they have an aligned vs unaligned access difference.(Related, I have been trying to make more code compliant under
-fsanitize=alignment
, which might makes memory access operations with hardware check easier.)