Commit 9679430d authored by Jose Dapena Paz's avatar Jose Dapena Paz Committed by Commit Bot

GCC fix: wrap CHECK asm in lambda to support constexpr calls

CHECK() implementation for arm, arm64, x86 and x64 includes
asm() statements. Recently added bounds checks using it
on constexpr methods are breaking GCC build, as GCC follows
more strictly C++14/11 standard, that explicitely forbids
calling asm from constexpr.

But GCC does not complain if the asm statement is not
directly called from constexpr, but through a function
call. So wrap the GCC asm calls for IMMEDIATE_CRASH in
a lambda function.

Bug: 821357
Change-Id: I9b806fa09eda872fb2b8e81cc79d8a4ea20e3e0b
Reviewed-on: https://chromium-review.googlesource.com/960861
Commit-Queue: José Dapena Paz <jose.dapena@lge.com>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543887}
parent 0b03fd17
......@@ -552,9 +552,26 @@ class CheckOpResult {
#define TRAP_SEQUENCE() __builtin_trap()
#endif // ARCH_CPU_*
// CHECK() and the trap sequence can be invoked from a constexpr function.
// This could make compilation fail on GCC, as it forbids directly using inline
// asm inside a constexpr function. However, it allows calling a lambda
// expression including the same asm.
// The side effect is that the top of the stacktrace will not point to the
// calling function, but to this anonymous lambda. This is still useful as the
// full name of the lambda will typically include the name of the function that
// calls CHECK() and the debugger will still break at the right line of code.
#if !defined(__clang__)
#define WRAPPED_TRAP_SEQUENCE() \
do { \
[] { TRAP_SEQUENCE(); }(); \
} while (false)
#else
#define WRAPPED_TRAP_SEQUENCE() TRAP_SEQUENCE()
#endif
#define IMMEDIATE_CRASH() \
({ \
TRAP_SEQUENCE(); \
WRAPPED_TRAP_SEQUENCE(); \
__builtin_unreachable(); \
})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment