Skip to content

Commit beb5e19

Browse files
committed
Enable -fextend-lifetimes at -Og
1 parent 3007f31 commit beb5e19

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
@@ -442,8 +442,11 @@ Code Generation Options
442442
:option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
443443
size further.
444444

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

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

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ Modified Compiler Flags
580580
``-fexperimental-modules-reduced-bmi`` flag. The ``-fmodules-reduced-bmi`` flag
581581
is intended to be enabled by default in the future.
582582

583+
- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``, a new
584+
compiler flag which trades a small amount of optimization in exchange for
585+
improved variable visibility.
586+
583587
Removed Compiler Flags
584588
-------------------------
585589

clang/lib/Driver/ToolChains/Clang.cpp

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

7709-
Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ);
7709+
if (Arg *A = Args.getLastArg(options::OPT_fextend_variable_liveness_EQ)) {
7710+
A->render(Args, CmdArgs);
7711+
} else if (Arg *A = Args.getLastArg(options::OPT_O_Group);
7712+
A && A->containsValue("g")) {
7713+
// Set -fextend-variable-liveness=all by default at -Og.
7714+
CmdArgs.push_back("-fextend-variable-liveness=all");
7715+
}
77107716

77117717
// Forward -fcomment-block-commands to -cc1.
77127718
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-this-ptr-liveness -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS

0 commit comments

Comments
 (0)