Skip to content

Commit d414ebf

Browse files
[Driver] Turn off optimization when -g option is passed.
1 parent c6001ee commit d414ebf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5600,8 +5600,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56005600
CmdArgs.push_back("-Wno-sycl-strict");
56015601
}
56025602

5603-
// Set O2 optimization level by default
5604-
if (!Args.getLastArg(options::OPT_O_Group))
5603+
// '-g' option turns off optimization -O2 and makes -O0 the default.
5604+
if (Arg *A = Args.getLastArg(options::OPT_g_Group)) {
5605+
if (A->getOption().matches(options::OPT_g_Flag))
5606+
CmdArgs.push_back("-O0");
5607+
}
5608+
// Set O2 optimization level by default if no -g option is passed.
5609+
if (!Args.getLastArg(options::OPT_O_Group) && !Args.getLastArg(options::OPT_g_Group))
56055610
CmdArgs.push_back("-O2");
56065611

56075612
// Add the integration header option to generate the header.
@@ -10806,6 +10811,13 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
1080610811

1080710812
// Partially copied from clang/lib/Frontend/CompilerInvocation.cpp
1080810813
static std::string getSYCLPostLinkOptimizationLevel(const ArgList &Args) {
10814+
10815+
// '-g' option turns off optimization -O2 and makes -O0 the default.
10816+
if(Arg *A = Args.getLastArg(options::OPT_g_Group)) {
10817+
if (A->getOption().matches(options::OPT_g_Flag))
10818+
return "-O0";
10819+
}
10820+
1080910821
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
1081010822
// Pass -O2 when the user passes -O0 due to IGC
1081110823
// debugging limitation. Note this only effects

0 commit comments

Comments
 (0)