Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clang/docs/CommandGuide/clang.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,11 @@ Code Generation Options
:option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
size further.

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

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

Expand Down
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ Modified Compiler Flags

- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets. (#GH125688)

- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``,
reducing performance slightly while reducing the number of optimized-out
variables.

Removed Compiler Flags
-------------------------

Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7681,7 +7681,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
CmdArgs.push_back("-fretain-comments-from-system-headers");

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

// Forward -fcomment-block-commands to -cc1.
Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
Expand Down
3 changes: 2 additions & 1 deletion clang/test/Driver/extend-variable-liveness.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Tests that -fextend-variable-liveness and its aliases are correctly passed
// by the driver.
// by the driver, and are set by default at -Og.

// RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DEFAULT
// RUN: %clang -### -Og -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL
// RUN: %clang -fextend-variable-liveness=none -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NONE
// RUN: %clang -fextend-variable-liveness=this -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS
// RUN: %clang -fextend-variable-liveness=all -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL
Expand Down
Loading