Index: clang/lib/Lex/Pragma.cpp =================================================================== --- clang/lib/Lex/Pragma.cpp +++ clang/lib/Lex/Pragma.cpp @@ -1145,16 +1145,24 @@ /*IsReinject=*/false); } +#ifdef __clang__ + __attribute__((optnone)) +#elif __GNUC__ + __attribute__((optimize("O0"))) +#elif _MSC_VER // Disable MSVC warning about runtime stack overflow. -#ifdef _MSC_VER - #pragma warning(disable : 4717) +#pragma warning(disable : 4717) +#pragma optimize("", off) #endif - static void DebugOverflowStack(void (*P)() = nullptr) { - void (*volatile Self)(void(*P)()) = DebugOverflowStack; - Self(reinterpret_cast(Self)); - } -#ifdef _MSC_VER - #pragma warning(default : 4717) + static void + DebugOverflowStack(void (*P)() = nullptr, unsigned *V = nullptr) { + unsigned A[16384]{1}; + void (*volatile Self)(void (*P)(), unsigned *) = DebugOverflowStack; + Self(reinterpret_cast(Self), A); + } +#if !defined(__clang__) && defined(_MSC_VER) +#pragma optimize("", on) +#pragma warning(default : 4717) #endif }; Index: clang/test/Driver/crash-report.c =================================================================== --- clang/test/Driver/crash-report.c +++ clang/test/Driver/crash-report.c @@ -21,12 +21,20 @@ // RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s // RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s +// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1 \ +// RUN: CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1 \ +// RUN: not %clang %s @%t.rsp -DOVERFLOW 2>&1 | FileCheck %s +// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s +// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s + // REQUIRES: crash-recovery #ifdef PARSER #pragma clang __debug parser_crash #elif CRASH #pragma clang __debug crash +#elif OVERFLOW +#pragma clang __debug overflow_stack #endif // CHECK: Preprocessed source(s) and associated run script(s) are located at: