Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
// RUN: %clang_cc1 -std=c90 -fconst-strings -DCONST_STRINGS -verify %s
|
|
|
|
// RUN: %clang_cc1 -std=c90 -verify %s
|
2023-05-19 11:57:49 -04:00
|
|
|
// RUN: %clang_cc1 -std=c90 -fms-extensions -DMS -fconst-strings -DCONST_STRINGS -verify %s
|
|
|
|
// RUN: %clang_cc1 -std=c90 -fms-extensions -DMS -verify %s
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
|
|
|
|
// expected-no-diagnostics
|
|
|
|
|
|
|
|
#define IsEqual(L, R) (__builtin_strcmp(L, R) == 0)
|
|
|
|
|
|
|
|
const char *const FILE = __builtin_FILE();
|
|
|
|
const char *const FUNC = __builtin_FUNCTION();
|
|
|
|
const unsigned LINE = __builtin_LINE();
|
|
|
|
const unsigned COL = __builtin_COLUMN();
|
|
|
|
|
|
|
|
#ifndef CONST_STRINGS
|
|
|
|
char *const NCFILE = __builtin_FILE();
|
|
|
|
char *const NCFUNC = __builtin_FUNCTION();
|
2023-05-19 11:57:49 -04:00
|
|
|
#ifdef MS
|
|
|
|
char *const NCFNSG = __builtin_FUNCSIG();
|
|
|
|
#endif
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONST_STRINGS
|
|
|
|
_Static_assert(IsEqual(__builtin_FILE(), __FILE__), "");
|
2023-03-17 09:50:34 -04:00
|
|
|
_Static_assert(IsEqual(__builtin_FILE_NAME(), __FILE_NAME__), "");
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
_Static_assert(__builtin_LINE() == __LINE__, "");
|
|
|
|
_Static_assert(IsEqual("", __builtin_FUNCTION()), "");
|
2023-05-19 11:57:49 -04:00
|
|
|
#ifdef MS
|
|
|
|
_Static_assert(IsEqual("", __builtin_FUNCSIG()), "");
|
|
|
|
#endif
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
|
|
|
|
#line 42 "my_file.c"
|
|
|
|
_Static_assert(__builtin_LINE() == 42, "");
|
|
|
|
_Static_assert(IsEqual(__builtin_FILE(), "my_file.c"), "");
|
2023-03-17 09:50:34 -04:00
|
|
|
_Static_assert(IsEqual(__builtin_FILE_NAME(), "my_file.c"), "");
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
|
|
|
|
_Static_assert(__builtin_COLUMN() == __builtin_strlen("_Static_assert(_"), "");
|
|
|
|
|
2022-02-07 09:24:09 -05:00
|
|
|
void foo(void) {
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
_Static_assert(IsEqual(__builtin_FUNCTION(), "foo"), "");
|
2023-05-19 11:57:49 -04:00
|
|
|
#ifdef MS
|
|
|
|
_Static_assert(IsEqual(__builtin_FUNCSIG(), "void __cdecl foo(void)"), "");
|
|
|
|
#endif
|
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong
Reviewed By: rsmith
Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits
Differential Revision: https://reviews.llvm.org/D37035
llvm-svn: 360937
2019-05-16 21:04:15 +00:00
|
|
|
}
|
|
|
|
#endif // CONST_STRINGS
|