[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
hstk30-hw wrote: Some project use `Werror` strictly, https://github.com/ClangBuiltLinux/linux/issues/306 add the `-no-deprecated-warn` option, but we can't pass the flags from clang to llvm-mc, change the makefile to use `llvm-mc` to generate obj just for some file is inconvenience. https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
https://github.com/MaskRay requested changes to this pull request. Agree that the motivation should be communicated. Driver options have stronger stability guarantee. If there are sufficient motivation and useful MCTargetOptions that we don't feel comfortable exposing driver options, I think this is probably fine. We probably don't want to test every option. Just 2 or 3 suffices. https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
aeubanks wrote: can you instead expose the options you want as proper clang flags? https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
https://github.com/fpetrogalli review_requested https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
https://github.com/fpetrogalli review_requested https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
llvmbot wrote: @llvm/pr-subscribers-clang Changes The cl::opt used by MCTargetOptions are not created until RegisterMCTargetOptionsFlags is instantiated. Due to this deferral the compiler driver -mllvm path is unable to parse flags such as --no-deprecated-warn which work properly in llvm-mc. Move the instantiation into the frontend and cc1as and propagate the results into MCTargetOptions. -- Full diff: https://github.com/llvm/llvm-project/pull/66347.diff 4 Files Affected: - (added) clang/test/Misc/cc1as-mllvm-mc-options.s (+12) - (added) clang/test/Misc/compiler-mllvm-mc-options.c (+12) - (modified) clang/tools/driver/cc1_main.cpp (+4) - (modified) clang/tools/driver/cc1as_main.cpp (+2-1) diff --git a/clang/test/Misc/cc1as-mllvm-mc-options.s b/clang/test/Misc/cc1as-mllvm-mc-options.s new file mode 100644 index 000..189e3c546b8fd94 --- /dev/null +++ b/clang/test/Misc/cc1as-mllvm-mc-options.s @@ -0,0 +1,12 @@ +// Ensure MCTargetOptionsCommandFlags are parsable under -mllvm +// RUN: %clang -cc1as -mllvm --help %s | FileCheck %s +// CHECK: --asm-show-inst +// CHECK: --dwarf-version +// CHECK: --dwarf64 +// CHECK: --emit-dwarf-unwind +// CHECK: --fatal-warnings +// CHECK: --incremental-linker-compatible +// CHECK: --mc-relax-all +// CHECK: --no-deprecated-warn +// CHECK: --no-type-check +// CHECK: --no-warn diff --git a/clang/test/Misc/compiler-mllvm-mc-options.c b/clang/test/Misc/compiler-mllvm-mc-options.c new file mode 100644 index 000..10b2a1172968d66 --- /dev/null +++ b/clang/test/Misc/compiler-mllvm-mc-options.c @@ -0,0 +1,12 @@ +// Ensure MCTargetOptionsCommandFlags are parsable under -mllvm +// RUN: %clang -mllvm --help -c %s -o /dev/null | FileCheck %s +// CHECK: --asm-show-inst +// CHECK: --dwarf-version +// CHECK: --dwarf64 +// CHECK: --emit-dwarf-unwind +// CHECK: --fatal-warnings +// CHECK: --incremental-linker-compatible +// CHECK: --mc-relax-all +// CHECK: --no-deprecated-warn +// CHECK: --no-type-check +// CHECK: --no-warn diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 9e7f8679b4cbdff..cc7089842a60c0d 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -28,6 +28,7 @@ #include quot;llvm/ADT/Statistic.hquot; #include quot;llvm/Config/llvm-config.hquot; #include quot;llvm/LinkAllPasses.hquot; +#include quot;llvm/MC/MCTargetOptionsCommandFlags.hquot; #include quot;llvm/MC/TargetRegistry.hquot; #include quot;llvm/Option/Arg.hquot; #include quot;llvm/Option/ArgList.hquot; @@ -53,6 +54,9 @@ using namespace clang; using namespace llvm::opt; +// Initialize MC Target option flags (for -mllvm) +static llvm::mc::RegisterMCTargetOptionsFlags MOF; + //===--===// // Main driver //===--===// diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 3c5926073f026a6..3eb7c8c555bf186 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -36,6 +36,7 @@ #include quot;llvm/MC/MCStreamer.hquot; #include quot;llvm/MC/MCSubtargetInfo.hquot; #include quot;llvm/MC/MCTargetOptions.hquot; +#include quot;llvm/MC/MCTargetOptionsCommandFlags.hquot; #include quot;llvm/MC/TargetRegistry.hquot; #include quot;llvm/Option/Arg.hquot; #include quot;llvm/Option/ArgList.hquot; @@ -408,7 +409,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation amp;Opts, std::unique_ptrlt;MCRegisterInfogt; MRI(TheTarget-gt;createMCRegInfo(Opts.Triple)); assert(MRI amp;amp; quot;Unable to create target register info!quot;); - MCTargetOptions MCOptions; + MCTargetOptions MCOptions = llvm::mc::InitMCTargetOptionsFromFlags(); MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/66347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)
https://github.com/fpetrogalli created https://github.com/llvm/llvm-project/pull/66347: The cl::opt used by MCTargetOptions are not created until RegisterMCTargetOptionsFlags is instantiated. Due to this deferral the compiler driver -mllvm path is unable to parse flags such as --no-deprecated-warn which work properly in llvm-mc. Move the instantiation into the frontend and cc1as and propagate the results into MCTargetOptions. >From 72aab7cf85b7a2c09faf84ddd6a2d29af27834a7 Mon Sep 17 00:00:00 2001 From: Stephan Lachowsky Date: Thu, 14 Sep 2023 11:11:19 +0200 Subject: [PATCH] [clang] Allow MCTargetOptions to be parseable by -mllvm. The cl::opt used by MCTargetOptions are not created until RegisterMCTargetOptionsFlags is instantiated. Due to this deferral the compiler driver -mllvm path is unable to parse flags such as --no-deprecated-warn which work properly in llvm-mc. Move the instantiation into the frontend and cc1as and propagate the results into MCTargetOptions. --- clang/test/Misc/cc1as-mllvm-mc-options.s| 12 clang/test/Misc/compiler-mllvm-mc-options.c | 12 clang/tools/driver/cc1_main.cpp | 4 clang/tools/driver/cc1as_main.cpp | 3 ++- 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 clang/test/Misc/cc1as-mllvm-mc-options.s create mode 100644 clang/test/Misc/compiler-mllvm-mc-options.c diff --git a/clang/test/Misc/cc1as-mllvm-mc-options.s b/clang/test/Misc/cc1as-mllvm-mc-options.s new file mode 100644 index 000..189e3c546b8fd94 --- /dev/null +++ b/clang/test/Misc/cc1as-mllvm-mc-options.s @@ -0,0 +1,12 @@ +// Ensure MCTargetOptionsCommandFlags are parsable under -mllvm +// RUN: %clang -cc1as -mllvm --help %s | FileCheck %s +// CHECK: --asm-show-inst +// CHECK: --dwarf-version +// CHECK: --dwarf64 +// CHECK: --emit-dwarf-unwind +// CHECK: --fatal-warnings +// CHECK: --incremental-linker-compatible +// CHECK: --mc-relax-all +// CHECK: --no-deprecated-warn +// CHECK: --no-type-check +// CHECK: --no-warn diff --git a/clang/test/Misc/compiler-mllvm-mc-options.c b/clang/test/Misc/compiler-mllvm-mc-options.c new file mode 100644 index 000..10b2a1172968d66 --- /dev/null +++ b/clang/test/Misc/compiler-mllvm-mc-options.c @@ -0,0 +1,12 @@ +// Ensure MCTargetOptionsCommandFlags are parsable under -mllvm +// RUN: %clang -mllvm --help -c %s -o /dev/null | FileCheck %s +// CHECK: --asm-show-inst +// CHECK: --dwarf-version +// CHECK: --dwarf64 +// CHECK: --emit-dwarf-unwind +// CHECK: --fatal-warnings +// CHECK: --incremental-linker-compatible +// CHECK: --mc-relax-all +// CHECK: --no-deprecated-warn +// CHECK: --no-type-check +// CHECK: --no-warn diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 9e7f8679b4cbdff..cc7089842a60c0d 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Config/llvm-config.h" #include "llvm/LinkAllPasses.h" +#include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" @@ -53,6 +54,9 @@ using namespace clang; using namespace llvm::opt; +// Initialize MC Target option flags (for -mllvm) +static llvm::mc::RegisterMCTargetOptionsFlags MOF; + //===--===// // Main driver //===--===// diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 3c5926073f026a6..3eb7c8c555bf186 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -36,6 +36,7 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptions.h" +#include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" @@ -408,7 +409,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation , std::unique_ptr MRI(TheTarget->createMCRegInfo(Opts.Triple)); assert(MRI && "Unable to create target register info!"); - MCTargetOptions MCOptions; + MCTargetOptions MCOptions = llvm::mc::InitMCTargetOptionsFromFlags(); MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits