Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4878,15 +4878,10 @@ // -stack-protector=0 is default. unsigned StackProtectorLevel = 0; - if (getToolChain().getSanitizerArgs().needsSafeStackRt()) { - Args.ClaimAllArgs(options::OPT_fno_stack_protector); - Args.ClaimAllArgs(options::OPT_fstack_protector_all); - Args.ClaimAllArgs(options::OPT_fstack_protector_strong); - Args.ClaimAllArgs(options::OPT_fstack_protector); - } else if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, - options::OPT_fstack_protector_all, - options::OPT_fstack_protector_strong, - options::OPT_fstack_protector)) { + if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, + options::OPT_fstack_protector_all, + options::OPT_fstack_protector_strong, + options::OPT_fstack_protector)) { if (A->getOption().matches(options::OPT_fstack_protector)) { StackProtectorLevel = std::max( LangOptions::SSPOn, Index: test/CodeGen/stack-protector.c =================================================================== --- test/CodeGen/stack-protector.c +++ test/CodeGen/stack-protector.c @@ -1,13 +1,13 @@ -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 0 | FileCheck -check-prefix=NOSSP %s -// NOSSP: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 1 | FileCheck -check-prefix=WITHSSP %s -// WITHSSP: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 2 | FileCheck -check-prefix=SSPSTRONG %s -// SSPSTRONG: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 3 | FileCheck -check-prefix=SSPREQ %s -// SSPREQ: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack | FileCheck -check-prefix=SAFESTACK %s -// SAFESTACK: define {{.*}}void @test1(i8* %msg) #0 { +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 0 | FileCheck -check-prefix=DEF -check-prefix=NOSSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 1 | FileCheck -check-prefix=DEF -check-prefix=SSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 2 | FileCheck -check-prefix=DEF -check-prefix=SSPSTRONG %s +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 3 | FileCheck -check-prefix=DEF -check-prefix=SSPREQ %s + +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-NOSSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 0 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-NOSSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 1 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 2 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSPSTRONG %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 3 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSPREQ %s typedef __SIZE_TYPE__ size_t; @@ -15,18 +15,21 @@ size_t strlen(const char *s); char *strcpy(char *s1, const char *s2); +// DEF: define {{.*}}void @test1(i8* %msg) #[[A:.*]] { void test1(const char *msg) { char a[strlen(msg) + 1]; strcpy(a, msg); printf("%s\n", a); } -// NOSSP: attributes #{{.*}} = { nounwind{{.*}} } - -// WITHSSP: attributes #{{.*}} = { nounwind ssp{{.*}} } - -// SSPSTRONG: attributes #{{.*}} = { nounwind sspstrong{{.*}} } +// NOSSP-NOT: attributes #[[A]] = {{.*}} ssp +// SSP: attributes #[[A]] = {{.*}} ssp +// SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong +// SSPREQ: attributes #[[A]] = {{.*}} sspreq -// SSPREQ: attributes #{{.*}} = { nounwind sspreq{{.*}} } +// SAFESTACK-NOSSP: attributes #[[A]] = {{.*}} safestack +// SAFESTACK-NOSSP-NOT: ssp -// SAFESTACK: attributes #{{.*}} = { nounwind safestack{{.*}} } +// SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp +// SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong +// SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq Index: test/Driver/fsanitize.c =================================================================== --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -317,16 +317,21 @@ // RUN: %clang -fno-sanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NOSP // NOSP-NOT: "-fsanitize=safe-stack" -// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP -// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP-ASAN +// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN // RUN: %clang -target x86_64-linux-gnu -fstack-protector -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP -// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP -// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP -// SP-NOT: stack-protector +// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP +// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP +// NO-SP-NOT: stack-protector +// NO-SP: "-fsanitize=safe-stack" // SP: "-fsanitize=safe-stack" -// SP-ASAN-NOT: stack-protector -// SP-ASAN: "-fsanitize=address,safe-stack" +// SP: -stack-protector +// NO-SP-NOT: stack-protector + +// NO-SP-ASAN-NOT: stack-protector +// NO-SP-ASAN: "-fsanitize=address,safe-stack" +// NO-SP-ASAN-NOT: stack-protector // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM