From f15e66bbbf39019264e6843f16331c21c5a27ed0 Mon Sep 17 00:00:00 2001 From: shivaramaarao <58245296+shivaramaarao@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:35:13 +0530 Subject: [PATCH] Fix for issue 1440 (#180) (#187) Through this commit Mbackslash will be the default option. By default, escape characters are treated as regular characters unless Mnobackslash is specified. There is also the issue of treating both Mbackslash and Mnobackslash options independently. This is addressed in this patch and the testcases in flang repository will test this feature. --- clang/lib/Driver/ToolChains/ClassicFlang.cpp | 35 ++++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/clang/lib/Driver/ToolChains/ClassicFlang.cpp b/clang/lib/Driver/ToolChains/ClassicFlang.cpp index 7755a0276025..2e91b7caa046 100644 --- a/clang/lib/Driver/ToolChains/ClassicFlang.cpp +++ b/clang/lib/Driver/ToolChains/ClassicFlang.cpp @@ -240,22 +240,35 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA, } } - // Treat backslashes as regular characters - for (auto Arg : Args.filtered(options::OPT_fno_backslash, options::OPT_Mbackslash)) { - Arg->claim(); + if (auto *A = + Args.getLastArg(options::OPT_fno_backslash, options::OPT_Mbackslash, + options::OPT_fbackslash, options::OPT_Mnobackslash)) { + for (auto Arg : + Args.filtered(options::OPT_fno_backslash, options::OPT_Mbackslash, + options::OPT_fbackslash, options::OPT_Mnobackslash)) { + Arg->claim(); + } + // Treat backslashes as regular characters + if (A->getOption().matches(options::OPT_fno_backslash) || + A->getOption().matches(options::OPT_Mbackslash)) { + CommonCmdArgs.push_back("-x"); + CommonCmdArgs.push_back("124"); + CommonCmdArgs.push_back("0x40"); + } + // Treat backslashes as C-style escape characters + if (A->getOption().matches(options::OPT_fbackslash) || + A->getOption().matches(options::OPT_Mnobackslash)) { + CommonCmdArgs.push_back("-y"); + CommonCmdArgs.push_back("124"); + CommonCmdArgs.push_back("0x40"); + } + } else { + // By default treat backslashes as regular characters CommonCmdArgs.push_back("-x"); CommonCmdArgs.push_back("124"); CommonCmdArgs.push_back("0x40"); } - // Treat backslashes as C-style escape characters - for (auto Arg : Args.filtered(options::OPT_fbackslash, options::OPT_Mnobackslash)) { - Arg->claim(); - CommonCmdArgs.push_back("-y"); - CommonCmdArgs.push_back("124"); - CommonCmdArgs.push_back("0x40"); - } - // handle OpemMP options if (auto *A = Args.getLastArg(options::OPT_mp, options::OPT_nomp, options::OPT_fopenmp, options::OPT_fno_openmp)) {