This is an archive of the discontinued LLVM Phabricator instance.

Fix "#pragma clang __debug overflow_stack" for MSVC builds
Needs ReviewPublic

Authored by gbedwell on Aug 28 2014, 1:34 PM.
This revision needs review, but all specified reviewers are disabled or inactive.

Details

Reviewers
espindola
Summary

Hi Clang Developers,

I noticed that using "#pragma clang __debug overflow_stack" on clang.exe built by Visual Studio 2012, to force a stack overflow causes it to seemingly hang indefinitely (I left it running overnight and it hadn't finished by morning). This patch just ensures that there is actually some new stack usage on every call to DebugOverflowStack. With this patch the overflow_stack pragma causes clang.exe to crash immediately with a big callstack full of DebugOverflowStack as I'd expect.

I've got a test for it, but when testing on Linux ran into the issue described at https://savannah.gnu.org/bugs/?22010 where GNU Make 3.81 has a bug where spawned processes get an unlimited stack size. Obviously this doesn't play well with a test designed to overflow the stack and brought the whole system to a halt. It works correctly when running through lit directly.

Here is my test for reference. Any suggestions to robustify it against the above behaviour are appreciated! I thought about adding a "REQUIRES: system-windows" but I'm not sure if some people may be using Make on Windows or whether it suffers from the same issue as on Linux.


RUN: not %clang %s -fsyntax-only 2>&1 | FileCheck %s
REQUIRES: crash-recovery

#pragma clang __debug overflow_stack

// CHECK: PLEASE submit a bug report

Otherwise, is it okay to commit the attached patch without the test?

Many Thanks,

Greg Bedwell
SN Systems - Sony Computer Entertainment Inc.

Diff Detail

Event Timeline

gbedwell updated this revision to Diff 13056.Aug 28 2014, 1:34 PM
gbedwell retitled this revision from to Fix "#pragma clang __debug overflow_stack" for MSVC builds.
gbedwell updated this object.
gbedwell edited the test plan for this revision. (Show Details)
gbedwell added a subscriber: Unknown Object (MLST).

...and right as I hit submit I realised I submitted my non-clang-formatted version, but Phabricator is not letting me submit an updated version at the moment. d'oh!

obviously should look like this:

void *StackUser = &StackUser;

rsmith added a subscriber: rsmith.Aug 28 2014, 2:39 PM
rsmith added inline comments.
lib/Lex/Pragma.cpp
928–932

A smart compiler could still optimize out the stack usage here. How about using something that keeps all the stack memory live, such as:

volatile void *Head;
static void DebugOverflowStack(void *Curr = 0) {
  Head = Curr;
  DebugOverflowStack(&Curr);
}

Hopefully MSVC doesn't optimize out stores to volatile globals...

rsmith added inline comments.Aug 28 2014, 2:40 PM
lib/Lex/Pragma.cpp
928–932

Sorry, should be

void *volatile Head;
rafael accepted this revision.Aug 28 2014, 2:42 PM
rafael added a reviewer: rafael.
rafael added a subscriber: rafael.

There is a FIXME in test/Makefile about moving the ULIMIT setting from the Makefile to lit. The Make bug you found is another reason to do it, but that can be in another patch.

lib/Lex/Pragma.cpp
929

Add a comment explaining what this is.

This revision is now accepted and ready to land.Aug 28 2014, 2:42 PM

Looks like patch was not committed. Does it still make sense?

espindola edited reviewers, added: espindola; removed: rafael.Mar 14 2018, 5:04 PM
This revision now requires review to proceed.Mar 14 2018, 5:04 PM