aganea created this revision. aganea added reviewers: rnk, hans. Herald added a project: clang. Herald added a subscriber: cfe-commits. aganea marked an inline comment as done. aganea added inline comments.
================ Comment at: clang/lib/Lex/Pragma.cpp:1148 +#ifdef __clang__ + __attribute__((optnone)) ---------------- Would it be better if we had something like `LLVM_[DISABLE|ENABLE]_OPT` in `Compiler.h` instead of the #ifdefs? That would map to `#pragma clang optimize [off|on]` (and corresponding #pragma on MSVC/GCC). Note that there's no way I know of to disable optimizations on a per-function basis on MSVC. Previously, `#pragma clang __debug overflow_stack` wasn't really working, the function was simply looping and not overflowing. I tested this in various configurations, with Clang 9, MSVC 2017/2019 and GCC 9 on Ubuntu. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D74229 Files: clang/lib/Lex/Pragma.cpp clang/test/Driver/crash-report.c 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: 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<void(*)()>(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<void (*)()>(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: 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<void(*)()>(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<void (*)()>(Self), A); + } +#if !defined(__clang__) && defined(_MSC_VER) +#pragma optimize("", on) +#pragma warning(default : 4717) #endif };
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits