wangpc created this revision. wangpc added reviewers: reames, craig.topper, asb, kito-cheng. Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson. Herald added a project: All. wangpc requested review of this revision. Herald added subscribers: cfe-commits, eopXD, MaskRay. Herald added a project: clang.
To match GCC. Options `-m[no-]strict-align` are aliases of `-m[no-]unaligned-access` in clang, but there is no corresponding option in GCC. Support of `-m[no-]unaligned-access` in GCC may be needed to align Clang/GCC. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155456 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Arch/RISCV.cpp clang/test/Driver/riscv-default-features.c clang/test/Driver/riscv-features.c Index: clang/test/Driver/riscv-features.c =================================================================== --- clang/test/Driver/riscv-features.c +++ clang/test/Driver/riscv-features.c @@ -24,6 +24,16 @@ // DEFAULT: "-target-feature" "-save-restore" // DEFAULT-NOT: "-target-feature" "+save-restore" +// RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | FileCheck %s -check-prefix=UNALIGNED-ACCESS +// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-unaligned-access 2>&1 | FileCheck %s -check-prefix=NO-UNALIGNED-ACCESS +// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | FileCheck %s -check-prefix=UNALIGNED-ACCESS +// RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | FileCheck %s -check-prefix=NO-UNALIGNED-ACCESS + +// UNALIGNED-ACCESS: "-target-feature" "+unaligned-scalar-mem" +// NO-UNALIGNED-ACCESS: "-target-feature" "-unaligned-scalar-mem" +// DEFAULT: "-target-feature" "-unaligned-scalar-mem" +// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem" + // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \ // RUN: | FileCheck %s -check-prefix=DEFAULT-LINUX // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \ Index: clang/test/Driver/riscv-default-features.c =================================================================== --- clang/test/Driver/riscv-default-features.c +++ clang/test/Driver/riscv-default-features.c @@ -3,8 +3,10 @@ // RV32: "target-features"="+32bit,+a,+c,+m,+relax, // RV32-SAME: -save-restore +// RV32-SAME: -unaligned-scalar-mem // RV64: "target-features"="+64bit,+a,+c,+m,+relax, // RV64-SAME: -save-restore +// RV64-SAME: -unaligned-scalar-mem // Dummy function int foo(void){ Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -167,6 +167,13 @@ else Features.push_back("-save-restore"); + // -mno-unaligned-access is default, unless -munaligned-access is specified. + if (Args.hasFlag(options::OPT_munaligned_access, + options::OPT_mno_unaligned_access, false)) + Features.push_back("+unaligned-scalar-mem"); + else + Features.push_back("-unaligned-scalar-mem"); + // Now add any that the user explicitly requested on the command line, // which may override the defaults. handleTargetFeaturesGroup(D, Triple, Args, Features, Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3811,9 +3811,9 @@ "in __riscv_v_fixed_vlen preprocessor define (RISC-V only)">; def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_Group>, - HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch only)">; + HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch/RISC-V only)">; def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group<m_Group>, - HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch only)">; + HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch/RISC-V only)">; } // let Flags = [TargetSpecific] def mstrict_align : Flag<["-"], "mstrict-align">, Alias<mno_unaligned_access>, Flags<[CC1Option,HelpHidden]>, HelpText<"Force all memory accesses to be aligned (same as mno-unaligned-access)">;
Index: clang/test/Driver/riscv-features.c =================================================================== --- clang/test/Driver/riscv-features.c +++ clang/test/Driver/riscv-features.c @@ -24,6 +24,16 @@ // DEFAULT: "-target-feature" "-save-restore" // DEFAULT-NOT: "-target-feature" "+save-restore" +// RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | FileCheck %s -check-prefix=UNALIGNED-ACCESS +// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-unaligned-access 2>&1 | FileCheck %s -check-prefix=NO-UNALIGNED-ACCESS +// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | FileCheck %s -check-prefix=UNALIGNED-ACCESS +// RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | FileCheck %s -check-prefix=NO-UNALIGNED-ACCESS + +// UNALIGNED-ACCESS: "-target-feature" "+unaligned-scalar-mem" +// NO-UNALIGNED-ACCESS: "-target-feature" "-unaligned-scalar-mem" +// DEFAULT: "-target-feature" "-unaligned-scalar-mem" +// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem" + // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \ // RUN: | FileCheck %s -check-prefix=DEFAULT-LINUX // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \ Index: clang/test/Driver/riscv-default-features.c =================================================================== --- clang/test/Driver/riscv-default-features.c +++ clang/test/Driver/riscv-default-features.c @@ -3,8 +3,10 @@ // RV32: "target-features"="+32bit,+a,+c,+m,+relax, // RV32-SAME: -save-restore +// RV32-SAME: -unaligned-scalar-mem // RV64: "target-features"="+64bit,+a,+c,+m,+relax, // RV64-SAME: -save-restore +// RV64-SAME: -unaligned-scalar-mem // Dummy function int foo(void){ Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -167,6 +167,13 @@ else Features.push_back("-save-restore"); + // -mno-unaligned-access is default, unless -munaligned-access is specified. + if (Args.hasFlag(options::OPT_munaligned_access, + options::OPT_mno_unaligned_access, false)) + Features.push_back("+unaligned-scalar-mem"); + else + Features.push_back("-unaligned-scalar-mem"); + // Now add any that the user explicitly requested on the command line, // which may override the defaults. handleTargetFeaturesGroup(D, Triple, Args, Features, Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3811,9 +3811,9 @@ "in __riscv_v_fixed_vlen preprocessor define (RISC-V only)">; def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_Group>, - HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch only)">; + HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch/RISC-V only)">; def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group<m_Group>, - HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch only)">; + HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch/RISC-V only)">; } // let Flags = [TargetSpecific] def mstrict_align : Flag<["-"], "mstrict-align">, Alias<mno_unaligned_access>, Flags<[CC1Option,HelpHidden]>, HelpText<"Force all memory accesses to be aligned (same as mno-unaligned-access)">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits