}s;
} udwords;
-#if (defined(__LP64__) || defined(__wasm__) || defined(__mips64)) || defined(__riscv)
+#if defined(__LP64__) || defined(__wasm__) || defined(__mips64) || \
+ defined(__riscv) || defined(_WIN64)
#define CRT_HAS_128BIT
#endif
+/* MSVC doesn't have a working 128bit integer type. Users should really compile
+ * compiler-rt with clang, but if they happen to be doing a standalone build for
+ * asan or something else, disable the 128 bit parts so things sort of work.
+ */
+#if defined(_MSC_VER) && !defined(__clang__)
+#undef CRT_HAS_128BIT
+#endif
+
#ifdef CRT_HAS_128BIT
typedef int ti_int __attribute__ ((mode (TI)));
typedef unsigned tu_int __attribute__ ((mode (TI)));
include(builtin-config-ix)
+# Indicate if this is an MSVC environment.
pythonize_bool(MSVC)
+# Indicate if the compiler for the builtins library was MSVC. If the builtins
+# compiler was clang-cl, we will enable some features that the host compiler
+# will not, like C99 _Complex and int128.
+set(BUILTINS_IS_MSVC OFF)
+if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
+ set(BUILTINS_IS_MSVC ON)
+endif()
+pythonize_bool(BUILTINS_IS_MSVC)
+
#TODO: Add support for Apple.
if (NOT APPLE)
foreach(arch ${BUILTIN_SUPPORTED_ARCH})
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- absvti2_test.c - Test __absvti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- addvti3_test.c - Test __addvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- ashlti3_test.c - Test __ashlti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- ashrti3_test.c - Test __ashrti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- clzti2_test.c - Test __clzti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- cmpti2_test.c - Test __cmpti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- ctzti2_test.c - Test __ctzti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- divti3_test.c - Test __divti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- fixdfti_test.c - Test __fixdfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- fixsfti_test.c - Test __fixsfti -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===//
//
// The LLVM Compiler Infrastructure
return 1;
#endif
- if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800LL))
+ if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800ULL))
return 1;
- if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000LL))
+ if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000ULL))
return 1;
- if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
+ if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00ULL))
return 1;
- if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
+ if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800ULL))
return 1;
- if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800LL, 0)))
+ if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800ULL, 0)))
return 1;
- if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000LL, 0)))
+ if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000ULL, 0)))
return 1;
- if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00LL, 0)))
+ if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00ULL, 0)))
return 1;
- if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800LL, 0)))
+ if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800ULL, 0)))
return 1;
- if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFLL,
- 0xFFFFFFFFFFFFFFFFLL)))
+ if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFULL,
+ 0xFFFFFFFFFFFFFFFFULL)))
return 1;
#if !TARGET_LIBGCC
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- fixunssfti_test.c - Test __fixunssfti -----------------------------===//
//
// The LLVM Compiler Infrastructure
return 1;
#endif
- if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL))
+ if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000ULL))
return 1;
- if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000LL))
+ if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000ULL))
return 1;
if (test__fixunssfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
return 1;
if (test__fixunssfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
return 1;
- if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000LL, 0)))
+ if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000ULL, 0)))
return 1;
- if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000LL, 0)))
+ if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000ULL, 0)))
return 1;
if (test__fixunssfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0)))
return 1;
#include "int_lib.h"
#include <stdio.h>
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
// Returns: convert a to a unsigned long long, rounding toward zero.
// Negative values all become zero.
int main()
{
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__fixunsxfti(0.0, 0))
return 1;
#include "int_lib.h"
#include <stdio.h>
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
// Returns: convert a to a signed long long, rounding toward zero.
return x != expected;
}
-char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
-char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
-char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
+COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int));
+COMPILE_TIME_ASSERT(sizeof(su_int)*CHAR_BIT == 32);
+COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);
#endif
int main()
{
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__fixxfti(0.0, 0))
return 1;
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- floattidf.c - Test __floattidf ------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- floattisf_test.c - Test __floattisf -------------------------------===//
//
// The LLVM Compiler Infrastructure
#include <float.h>
#include <stdio.h>
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
// Returns: convert a to a long double, rounding toward even.
return x != expected;
}
-char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
-char assumption_2[sizeof(ti_int)*CHAR_BIT == 128] = {0};
-char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
+COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int));
+COMPILE_TIME_ASSERT(sizeof(ti_int)*CHAR_BIT == 128);
+COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);
#endif
int main()
{
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__floattixf(0, 0.0))
return 1;
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- floatuntidf.c - Test __floatuntidf --------------------------------===//
//
// The LLVM Compiler Infrastructure
#include <float.h>
#include <stdio.h>
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
// Returns: convert a to a float, rounding toward even.
return x != expected;
}
-char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
-char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
-char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
+COMPILE_TIME_ASSERT(sizeof(tu_int) == 2*sizeof(du_int));
+COMPILE_TIME_ASSERT(sizeof(tu_int)*CHAR_BIT == 128);
+COMPILE_TIME_ASSERT(sizeof(float)*CHAR_BIT == 32);
#endif
int main()
{
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__floatuntisf(0, 0.0F))
return 1;
#include <float.h>
#include <stdio.h>
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
// Returns: convert a to a long double, rounding toward even.
return x != expected;
}
-char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
-char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
-char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
+COMPILE_TIME_ASSERT(sizeof(tu_int) == 2*sizeof(du_int));
+COMPILE_TIME_ASSERT(sizeof(tu_int)*CHAR_BIT == 128);
+COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);
#endif
int main()
{
-#ifdef CRT_HAS_128BIT
+#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
if (test__floatuntixf(0, 0.0))
return 1;
config.test_source_root = os.path.dirname(__file__)
# Path to the static library
-is_msvc = get_required_attr(config, "builtins_is_msvc")
+is_msvc = get_required_attr(config, "is_msvc")
if is_msvc:
base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins%s.lib "
% config.target_suffix)
clang_builtins_cflags = clang_builtins_static_cflags
clang_builtins_cxxflags = clang_builtins_static_cxxflags
+# FIXME: Right now we don't compile the C99 complex builtins when using
+# clang-cl. Fix that.
if not is_msvc:
config.available_features.add('c99-complex')
+builtins_is_msvc = get_required_attr(config, "builtins_is_msvc")
+if not builtins_is_msvc:
+ config.available_features.add('int128')
+
clang_wrapper = ""
def build_invocation(compile_flags):
config.builtins_lit_source_dir = "@BUILTINS_LIT_SOURCE_DIR@/Unit"
config.target_cflags = "@BUILTINS_TEST_TARGET_CFLAGS@"
config.target_arch = "@BUILTINS_TEST_TARGET_ARCH@"
-config.builtins_is_msvc = @MSVC_PYBOOL@
+config.is_msvc = @MSVC_PYBOOL@
+config.builtins_is_msvc = @BUILTINS_IS_MSVC_PYBOOL@
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- lshrti3_test.c - Test __lshrti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- modti3_test.c - Test __modti3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
if (test__modti3(-5, -3, -2))
return 1;
- if (test__modti3(0x8000000000000000LL, 1, 0x0LL))
+ if (test__modti3(0x8000000000000000ULL, 1, 0x0LL))
return 1;
- if (test__modti3(0x8000000000000000LL, -1, 0x0LL))
+ if (test__modti3(0x8000000000000000ULL, -1, 0x0LL))
return 1;
- if (test__modti3(0x8000000000000000LL, 2, 0x0LL))
+ if (test__modti3(0x8000000000000000ULL, 2, 0x0LL))
return 1;
- if (test__modti3(0x8000000000000000LL, -2, 0x0LL))
+ if (test__modti3(0x8000000000000000ULL, -2, 0x0LL))
return 1;
- if (test__modti3(0x8000000000000000LL, 3, 2))
+ if (test__modti3(0x8000000000000000ULL, 3, 2))
return 1;
- if (test__modti3(0x8000000000000000LL, -3, 2))
+ if (test__modti3(0x8000000000000000ULL, -3, 2))
return 1;
if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- multi3_test.c - Test __multi3 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
return 1;
- if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001LL))
+ if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001ULL))
return 1;
if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
return 1;
if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
return 1;
- if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
+ if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001ULL))
return 1;
if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
return 1;
- if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656LL))
+ if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656ULL))
return 1;
if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
return 1;
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- negti2_test.c - Test __negti2 -------------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- negvti2_test.c - Test __negvti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- parityti2_test.c - Test __parityti2 -------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- popcountti2_test.c - Test __popcountti2 ----------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- subvti3_test.c - Test __subvti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- ucmpti2_test.c - Test __ucmpti2 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- udivmodti4_test.c - Test __udivmodti4 -----------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- udivti3_test.c - Test __udivti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure
// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: int128
//===-- umodti3_test.c - Test __umodti3 -----------------------------------===//
//
// The LLVM Compiler Infrastructure