Skip to content

Commit 351971b

Browse files
committed
Enable -fextend-lifetimes at -Og
1 parent d69ee88 commit 351971b

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

clang/docs/CommandGuide/clang.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,11 @@ Code Generation Options
443443
:option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
444444
size further.
445445

446-
:option:`-Og` Like :option:`-O1`. In future versions, this option might
447-
disable different optimizations in order to improve debuggability.
446+
:option:`-Og` Similar to :option:`-O1`, but with slightly reduced
447+
optimization and better variable visibility. The same optimizations are run
448+
as at :option:`-O1`, but the :option:`-fextend-variable-liveness` flag is
449+
also set, which tries to prevent optimizations from reducing the liveness of
450+
user variables, improving their availability when debugging.
448451

449452
:option:`-O` Equivalent to :option:`-O1`.
450453

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ Modified Compiler Flags
219219

220220
- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702
221221

222+
- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``, a new
223+
compiler flag which trades a small amount of optimization in exchange for
224+
improved variable visibility.
225+
222226
Removed Compiler Flags
223227
-------------------------
224228

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7681,7 +7681,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
76817681
if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
76827682
CmdArgs.push_back("-fretain-comments-from-system-headers");
76837683

7684-
Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ);
7684+
if (Arg *A = Args.getLastArg(options::OPT_fextend_variable_liveness_EQ)) {
7685+
A->render(Args, CmdArgs);
7686+
} else if (Arg *A = Args.getLastArg(options::OPT_O_Group);
7687+
A && A->containsValue("g")) {
7688+
// Set -fextend-variable-liveness=all by default at -Og.
7689+
CmdArgs.push_back("-fextend-variable-liveness=all");
7690+
}
76857691

76867692
// Forward -fcomment-block-commands to -cc1.
76877693
Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);

clang/test/Driver/extend-variable-liveness.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Tests that -fextend-variable-liveness and its aliases are correctly passed
2-
// by the driver.
2+
// by the driver, and are set by default at -Og.
33

44
// RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DEFAULT
5+
// RUN: %clang -### -Og -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL
56
// RUN: %clang -fextend-variable-liveness=none -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NONE
67
// RUN: %clang -fextend-variable-liveness=this -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS
78
// RUN: %clang -fextend-variable-liveness=all -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL

0 commit comments

Comments
 (0)