From 993a1398473ecf3e5deb62350aac4356d061e99f Mon Sep 17 00:00:00 2001 From: Nirav Dave Date: Wed, 27 Jul 2016 19:57:40 +0000 Subject: [PATCH] Add flags to toggle preservation of assembly comments Summary: Add -fpreserve-as-comments and -fno-preserve-as-comments. Reviewers: echristo, rnk Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D22883 llvm-svn: 276907 --- clang/include/clang/Driver/Options.td | 3 +++ clang/include/clang/Frontend/CodeGenOptions.def | 1 + clang/lib/CodeGen/BackendUtil.cpp | 1 + clang/lib/Driver/Tools.cpp | 4 ++++ clang/lib/Frontend/CompilerInvocation.cpp | 1 + clang/test/CodeGen/preserve-as-comments.c | 12 ++++++++++++ 6 files changed, 22 insertions(+) create mode 100644 clang/test/CodeGen/preserve-as-comments.c diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 853fdcd..a6925fc 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1089,6 +1089,9 @@ def fpie : Flag<["-"], "fpie">, Group; def fno_pie : Flag<["-"], "fno-pie">, Group; def fplugin_EQ : Joined<["-"], "fplugin=">, Group, Flags<[DriverOption]>, MetaVarName<"">, HelpText<"Load the named plugin (dynamic shared object)">; +def fpreserve_as_comments : Flag<["-"], "fpreserve-as-comments">, Group; +def fno_preserve_as_comments : Flag<["-"], "fno-preserve-as-comments">, Group, Flags<[CC1Option]>, + HelpText<"Do not preserve comments in inline assembly">; def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group; def fno_profile_arcs : Flag<["-"], "fno-profile-arcs">, Group; def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>; diff --git a/clang/include/clang/Frontend/CodeGenOptions.def b/clang/include/clang/Frontend/CodeGenOptions.def index 6a4474c..bc2bde8 100644 --- a/clang/include/clang/Frontend/CodeGenOptions.def +++ b/clang/include/clang/Frontend/CodeGenOptions.def @@ -32,6 +32,7 @@ CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as CODEGENOPT(CompressDebugSections, 1, 0) ///< -Wa,-compress-debug-sections CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm. +CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments. CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe. diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 282468f..e5d4930 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -604,6 +604,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { CodeGenOpts.IncrementalLinkerCompatible; Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings; Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose; + Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments; Options.MCOptions.ABIName = TargetOpts.ABI; TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr, diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index bd306dd..e850fc2 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -4193,6 +4193,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, true)) CmdArgs.push_back("-fno-jump-tables"); + if (!Args.hasFlag(options::OPT_fpreserve_as_comments, + options::OPT_fno_preserve_as_comments, true)) + CmdArgs.push_back("-fno-preserve-as-comments"); + if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) { CmdArgs.push_back("-mregparm"); CmdArgs.push_back(A->getValue()); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 543cca7f..04da248 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -544,6 +544,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Args.hasFlag(OPT_fcoverage_mapping, OPT_fno_coverage_mapping, false); Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping); Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); + Opts.PreserveAsmComments = !Args.hasArg(OPT_fno_preserve_as_comments); Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); diff --git a/clang/test/CodeGen/preserve-as-comments.c b/clang/test/CodeGen/preserve-as-comments.c new file mode 100644 index 0000000..a145ca0 --- /dev/null +++ b/clang/test/CodeGen/preserve-as-comments.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -S -fno-preserve-as-comments %s -o - | FileCheck %s --check-prefix=NOASM --check-prefix=CHECK +// RUN: %clang_cc1 -S %s -o - | FileCheck %s --check-prefix=ASM --check-prefix=CHECK + +// CHECK-LABEL: main +// CHECK: #APP +// ASM: #comment +// NOASM-NOT: #comment +// CHECK: #NO_APP +int main() { + __asm__("/*comment*/"); + return 0; +} -- 2.7.4