[clang] ea0dae0 - [RISCV] Add Tag_RISCV_arch attribute by default when using clang as an assembler.

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 21 10:54:36 PDT 2023


Author: Craig Topper
Date: 2023-04-21T10:54:24-07:00
New Revision: ea0dae0961897da69b960caf68063db86312674d

URL: https://github.com/llvm/llvm-project/commit/ea0dae0961897da69b960caf68063db86312674d
DIFF: https://github.com/llvm/llvm-project/commit/ea0dae0961897da69b960caf68063db86312674d.diff

LOG: [RISCV] Add Tag_RISCV_arch attribute by default when using clang as an assembler.

Can be disabled with -mno-default-build-attributes just like ARM.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D148817

Added: 
    clang/test/Driver/riscv-default-build-attributes.s

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 7676cbe5e6c0e..56250fccfa855 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7903,6 +7903,12 @@ void ClangAs::AddRISCVTargetArgs(const ArgList &Args,
 
   CmdArgs.push_back("-target-abi");
   CmdArgs.push_back(ABIName.data());
+
+  if (Args.hasFlag(options::OPT_mdefault_build_attributes,
+                   options::OPT_mno_default_build_attributes, true)) {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-riscv-add-build-attributes");
+  }
 }
 
 void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,

diff  --git a/clang/test/Driver/riscv-default-build-attributes.s b/clang/test/Driver/riscv-default-build-attributes.s
new file mode 100644
index 0000000000000..5d2e08371cb5d
--- /dev/null
+++ b/clang/test/Driver/riscv-default-build-attributes.s
@@ -0,0 +1,29 @@
+//// Enabled by default for assembly
+// RUN: %clang --target=riscv32 -### %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-ENABLED
+// RUN: %clang --target=riscv64 -### %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang --target=riscv32 -### %s 2>&1 -mno-default-build-attributes \
+// RUN:   | FileCheck %s --check-prefix=CHECK-DISABLED
+// RUN: %clang --target=riscv64 -### %s 2>&1 -mno-default-build-attributes \
+// RUN:   | FileCheck %s --check-prefix=CHECK-DISABLED
+// RUN: %clang --target=riscv32 -### %s 2>&1 -mdefault-build-attributes \
+// RUN:   | FileCheck %s --check-prefix=CHECK-ENABLED
+// RUN: %clang --target=riscv64 -### %s 2>&1 -mdefault-build-attributes \
+// RUN:   | FileCheck %s --check-prefix=CHECK-ENABLED
+
+/// Option ignored for C/C++ (since we always emit hardware and ABI build
+/// attributes during codegen).
+// RUN: %clang --target=riscv32 -### -x c %s -mdefault-build-attributes 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-DISABLED
+// RUN: %clang --target=riscv64 -### -x c %s -mdefault-build-attributes 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-DISABLED
+// RUN: %clang --target=riscv32 -### -x c++ %s -mdefault-build-attributes 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-DISABLED
+// RUN: %clang --target=riscv64 -### -x c++ %s -mdefault-build-attributes 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-riscv-add-build-attributes"
+// CHECK-ENABLED: "-riscv-add-build-attributes"


        


More information about the cfe-commits mailing list