Skip to content

Commit 4b3eefa

Browse files
committedApr 5, 2018
Disable -fmerge-all-constants as default.
Summary: "-fmerge-all-constants" is a non-conforming optimization and should not be the default. It is also causing miscompiles when building Linux Kernel (https://lkml.org/lkml/2018/3/20/872). Fixes PR18538. Reviewers: rjmccall, rsmith, chandlerc Reviewed By: rsmith, chandlerc Subscribers: srhines, cfe-commits Differential Revision: https://reviews.llvm.org/D45289 llvm-svn: 329300
1 parent bbf98ae commit 4b3eefa

File tree

11 files changed

+28
-19
lines changed

11 files changed

+28
-19
lines changed
 

Diff for: ‎clang/include/clang/Driver/Options.td

+3-2
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,8 @@ def fthinlto_index_EQ : Joined<["-"], "fthinlto-index=">,
11331133
HelpText<"Perform ThinLTO importing using provided function summary index">;
11341134
def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
11351135
Group<f_Group>, Flags<[DriverOption, CoreOption]>;
1136-
def fmerge_all_constants : Flag<["-"], "fmerge-all-constants">, Group<f_Group>;
1136+
def fmerge_all_constants : Flag<["-"], "fmerge-all-constants">, Group<f_Group>,
1137+
Flags<[CC1Option]>, HelpText<"Allow merging of constants">;
11371138
def fmessage_length_EQ : Joined<["-"], "fmessage-length=">, Group<f_Group>;
11381139
def fms_extensions : Flag<["-"], "fms-extensions">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,
11391140
HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">;
@@ -1282,7 +1283,7 @@ def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>, Flags<[CC1Option]>,
12821283
def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>,
12831284
HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">, Flags<[CC1Option]>;
12841285
def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group<f_Group>,
1285-
Flags<[CC1Option]>, HelpText<"Disallow merging of constants">;
1286+
HelpText<"Disallow merging of constants">;
12861287
def fno_modules : Flag <["-"], "fno-modules">, Group<f_Group>,
12871288
Flags<[DriverOption]>;
12881289
def fno_implicit_module_maps : Flag <["-"], "fno-implicit-module-maps">, Group<f_Group>,

Diff for: ‎clang/lib/AST/ExprConstant.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -8596,9 +8596,6 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
85968596
(LHSValue.Base && isZeroSized(RHSValue)))
85978597
return Error(E);
85988598
// Pointers with different bases cannot represent the same object.
8599-
// (Note that clang defaults to -fmerge-all-constants, which can
8600-
// lead to inconsistent results for comparisons involving the address
8601-
// of a constant; this generally doesn't matter in practice.)
86028599
return Success(E->getOpcode() == BO_NE, E);
86038600
}
86048601

Diff for: ‎clang/lib/Driver/ToolChains/Clang.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3361,9 +3361,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
33613361

33623362
Args.AddLastArg(CmdArgs, options::OPT_fveclib);
33633363

3364-
if (!Args.hasFlag(options::OPT_fmerge_all_constants,
3365-
options::OPT_fno_merge_all_constants))
3366-
CmdArgs.push_back("-fno-merge-all-constants");
3364+
if (Args.hasFlag(options::OPT_fmerge_all_constants,
3365+
options::OPT_fno_merge_all_constants, false))
3366+
CmdArgs.push_back("-fmerge-all-constants");
33673367

33683368
// LLVM Code Generator Options.
33693369

Diff for: ‎clang/lib/Frontend/CompilerInvocation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
605605
Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
606606
OPT_fno_fine_grained_bitfield_accesses, false);
607607
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
608-
Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
608+
Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
609609
Opts.NoCommon = Args.hasArg(OPT_fno_common);
610610
Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
611611
Opts.OptimizeSize = getOptimizationLevelSize(Args);

Diff for: ‎clang/test/CodeGen/array-init.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-linux-gnu -emit-llvm -o - | FileCheck %s
1+
// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-linux-gnu -emit-llvm -o - | FileCheck -check-prefix=CHECK-NO-MERGE-CONSTANTS %s
2+
// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-linux-gnu -fmerge-all-constants -emit-llvm -o - | FileCheck -check-prefix=CHECK-MERGE-CONSTANTS %s
23

3-
// CHECK: @{{.*}}.a1 = internal constant [5 x i32] [i32 0, i32 1, i32 2, i32 0, i32 0]
4-
// CHECK: @{{.*}}.a2 = internal constant [5 x i32] zeroinitializer
5-
// CHECK: @{{.*}}.a3 = internal constant [5 x i32] zeroinitializer
4+
// CHECK-NO-MERGE-CONSTANTS: @{{.*}}.a1 = private unnamed_addr constant [5 x i32] [i32 0, i32 1, i32 2, i32 0, i32 0]
5+
6+
// CHECK-MERGE-CONSTANTS: @{{.*}}.a1 = internal constant [5 x i32] [i32 0, i32 1, i32 2, i32 0, i32 0]
7+
// CHECK-MERGE-CONSTANTS: @{{.*}}.a2 = internal constant [5 x i32] zeroinitializer
8+
// CHECK-MERGE-CONSTANTS: @{{.*}}.a3 = internal constant [5 x i32] zeroinitializer
69

710
void testConstArrayInits(void)
811
{

Diff for: ‎clang/test/CodeGen/decl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -w -emit-llvm < %s | FileCheck %s
1+
// RUN: %clang_cc1 -w -fmerge-all-constants -emit-llvm < %s | FileCheck %s
22

33
// CHECK: @test1.x = internal constant [12 x i32] [i32 1
44
// CHECK: @test2.x = private unnamed_addr constant [13 x i32] [i32 1,

Diff for: ‎clang/test/CodeGenCXX/const-init-cxx11.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -w -triple x86_64-elf-gnu -emit-llvm -o - %s -std=c++11 | FileCheck %s
1+
// RUN: %clang_cc1 -w -fmerge-all-constants -triple x86_64-elf-gnu -emit-llvm -o - %s -std=c++11 | FileCheck %s
22

33
// FIXME: The padding in all these objects should be zero-initialized.
44
namespace StructUnion {

Diff for: ‎clang/test/CodeGenCXX/cxx0x-initializer-references.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s
22

33
namespace reference {
44
struct A {

Diff for: ‎clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=X86,CHECK %s
2-
// RUN: %clang_cc1 -std=c++11 -triple amdgcn-amd-amdhsa -DNO_TLS -emit-llvm -o - %s | FileCheck -check-prefixes=AMDGCN,CHECK %s
1+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -fmerge-all-constants -emit-llvm -o - %s | FileCheck -check-prefixes=X86,CHECK %s
2+
// RUN: %clang_cc1 -std=c++11 -triple amdgcn-amd-amdhsa -DNO_TLS -fmerge-all-constants -emit-llvm -o - %s | FileCheck -check-prefixes=AMDGCN,CHECK %s
33

44
namespace std {
55
typedef decltype(sizeof(int)) size_t;

Diff for: ‎clang/test/CodeGenObjCXX/arc-cxx11-init-list.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fmerge-all-constants -fobjc-arc -Os -emit-llvm -o - %s | FileCheck %s
22

33
// CHECK: @[[STR0:.*]] = private unnamed_addr constant [5 x i8] c"str0\00", section "__TEXT,__cstring,cstring_literals"
44
// CHECK: @[[UNNAMED_CFSTRING0:.*]] = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR0]], i32 0, i32 0), i32 4 }, section "__DATA,__cfstring"

Diff for: ‎clang/test/Driver/clang_f_opts.c

+8
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@
276276
// RUN: -fno-inline-small-functions -finline-small-functions \
277277
// RUN: -fno-fat-lto-objects -ffat-lto-objects \
278278
// RUN: -fno-merge-constants -fmerge-constants \
279+
// RUN: -fno-merge-all-constants -fmerge-all-constants \
279280
// RUN: -fno-caller-saves -fcaller-saves \
280281
// RUN: -fno-reorder-blocks -freorder-blocks \
281282
// RUN: -fno-schedule-insns2 -fschedule-insns2 \
@@ -522,3 +523,10 @@
522523
// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s
523524
// CHECK-DISCARD-NAMES: "-discard-value-names"
524525
// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names"
526+
//
527+
// RUN: %clang -### -S -fmerge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-MERGE-ALL-CONSTANTS %s
528+
// RUN: %clang -### -S -fno-merge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MERGE-ALL-CONSTANTS %s
529+
// RUN: %clang -### -S -fmerge-all-constants -fno-merge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MERGE-ALL-CONSTANTS %s
530+
// RUN: %clang -### -S -fno-merge-all-constants -fmerge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-MERGE-ALL-CONSTANTS %s
531+
// CHECK-NO-MERGE-ALL-CONSTANTS-NOT: "-fmerge-all-constants"
532+
// CHECK-MERGE-ALL-CONSTANTS: "-fmerge-all-constants"

0 commit comments

Comments
 (0)
Please sign in to comment.