From dc67376e45d5028afc8686397621aa0a2e83fe88 Mon Sep 17 00:00:00 2001 From: shivaramaarao <58245296+shivaramaarao@users.noreply.github.com> Date: Wed, 3 Jul 2024 11:51:55 +0530 Subject: [PATCH] Fix for issue 1440 (#180) 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 b8be0be20b07..c04af3b19d2f 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)) {