Files
carbon-lang/common/preserve_none.h
T
Chandler Carruth f27a977d86 Fix ASan CI failures due to preserve_none (#8045)
These only show up post-merge as we're only running ASan there.

This disables the recent `[[clang::preserve_none]]` optimization when
ASan is enabled as there is an LLVM bug on AArch64 that causes register
corruption with that calling convention. This is factored into a common
helper library so we can use it in other places as well.

Assisted-by: Antigravity with Gemini
2026-10-27 21:05:53 +00:00

26 lines
1.0 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_COMMON_PRESERVE_NONE_H_
#define CARBON_COMMON_PRESERVE_NONE_H_
#include "llvm/Support/Compiler.h"
// Applies `[[clang::preserve_none]]` when supported and safe.
//
// Disabled when building with AddressSanitizer on AArch64 to work around an
// LLVM backend bug: when sanitizer stack instrumentation combines dynamic stack
// allocation with stack realignment, AArch64 reserves `x19` as the stack base
// pointer (`hasBasePointer`) and fails to save and restore `x19` across calls
// to `[[clang::preserve_none]]` callees that clobber `x19`.
#if __has_cpp_attribute(clang::preserve_none) && \
!((defined(__aarch64__) || defined(_M_ARM64)) && \
(LLVM_ADDRESS_SANITIZER_BUILD || LLVM_HWADDRESS_SANITIZER_BUILD))
#define CARBON_PRESERVE_NONE [[clang::preserve_none]]
#else
#define CARBON_PRESERVE_NONE
#endif
#endif // CARBON_COMMON_PRESERVE_NONE_H_