Skip to content

Commit 2b59ce7

Browse files
committed
Enable -fextend-lifetimes at -Og
1 parent efd7f58 commit 2b59ce7

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
@@ -455,6 +455,10 @@ Modified Compiler Flags
455455
``memset`` and similar functions for which it is a documented undefined
456456
behavior. It is implied by ``-Wnontrivial-memaccess``
457457

458+
- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``, a new
459+
compiler flag which trades a small amount of optimization in exchange for
460+
improved variable visibility.
461+
458462
Removed Compiler Flags
459463
-------------------------
460464

clang/lib/Driver/ToolChains/Clang.cpp

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

7657-
Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ);
7657+
if (Arg *A = Args.getLastArg(options::OPT_fextend_variable_liveness_EQ)) {
7658+
A->render(Args, CmdArgs);
7659+
} else if (Arg *A = Args.getLastArg(options::OPT_O_Group);
7660+
A && A->containsValue("g")) {
7661+
// Set -fextend-variable-liveness=all by default at -Og.
7662+
CmdArgs.push_back("-fextend-variable-liveness=all");
7663+
}
76587664

76597665
// Forward -fcomment-block-commands to -cc1.
76607666
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)