From 586831b2b098fe572b34f411ddaff3b21b053a4b Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 29 May 2019 03:15:36 +0000 Subject: [PATCH] Make __has_builtin work with __builtin_LINE and friends. The source location builtins are implemented as keywords, but __has_builtin should still report true for them. This patch also fixes a test failure on systemz where the alignment of string literals is 2 not 1. llvm-svn: 361920 --- clang/lib/Lex/PPMacroExpansion.cpp | 4 ++++ clang/test/CodeGenCXX/builtin_FUNCTION.cpp | 8 ++++---- clang/test/Preprocessor/feature_tests.c | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 4576f1a47e15..72f8f48839d0 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1620,6 +1620,10 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { .Case("__is_target_vendor", true) .Case("__is_target_os", true) .Case("__is_target_environment", true) + .Case("__builtin_LINE", true) + .Case("__builtin_FILE", true) + .Case("__builtin_FUNCTION", true) + .Case("__builtin_COLUMN", true) .Default(false); } }); diff --git a/clang/test/CodeGenCXX/builtin_FUNCTION.cpp b/clang/test/CodeGenCXX/builtin_FUNCTION.cpp index b3156ea45ae6..02e616351a93 100644 --- a/clang/test/CodeGenCXX/builtin_FUNCTION.cpp +++ b/clang/test/CodeGenCXX/builtin_FUNCTION.cpp @@ -6,7 +6,7 @@ namespace test_func { constexpr const char *test_default_arg(const char *f = __builtin_FUNCTION()) { return f; } -// CHECK: @[[EMPTY_STR:.+]] = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 +// CHECK: @[[EMPTY_STR:.+]] = private unnamed_addr constant [1 x i8] zeroinitializer // CHECK: @_ZN9test_func6globalE = {{(dso_local )?}}global i8* getelementptr inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0) const char *global = test_default_arg(); @@ -16,9 +16,9 @@ const char *global_two = __builtin_FUNCTION(); const char * const global_three = test_default_arg(); -// CHECK: @[[STR_ONE:.+]] = private unnamed_addr constant [14 x i8] c"test_func_one\00", align 1 -// CHECK: @[[STR_TWO:.+]] = private unnamed_addr constant [14 x i8] c"test_func_two\00", align 1 -// CHECK: @[[STR_THREE:.+]] = private unnamed_addr constant [20 x i8] c"do_default_arg_test\00", align 1 +// CHECK: @[[STR_ONE:.+]] = private unnamed_addr constant [14 x i8] c"test_func_one\00" +// CHECK: @[[STR_TWO:.+]] = private unnamed_addr constant [14 x i8] c"test_func_two\00" +// CHECK: @[[STR_THREE:.+]] = private unnamed_addr constant [20 x i8] c"do_default_arg_test\00" // CHECK: define {{(dso_local )?}}i8* @_ZN9test_func13test_func_oneEv() // CHECK: ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @[[STR_ONE]], i32 0, i32 0) diff --git a/clang/test/Preprocessor/feature_tests.c b/clang/test/Preprocessor/feature_tests.c index c2fbd11c97cd..2035a729f2d0 100644 --- a/clang/test/Preprocessor/feature_tests.c +++ b/clang/test/Preprocessor/feature_tests.c @@ -20,6 +20,15 @@ #error Clang should have these #endif +// These are technically implemented as keywords, but __has_builtin should +// still return true. +#if !__has_builtin(__builtin_LINE) || \ + !__has_builtin(__builtin_FILE) || \ + !__has_builtin(__builtin_FUNCTION) || \ + !__has_builtin(__builtin_COLUMN) +#error Clang should have these +#endif + #if __has_builtin(__builtin_insanity) #error Clang should not have this #endif