summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2022-11-02 07:56:43 -0400
committerTom Stellard <tstellar@redhat.com>2022-11-10 16:55:23 -0800
commit931b6d51d84e2a5cbbdc925d546819d4d3b7c63e (patch)
tree0caa2fdad0379b2190560b39eeac0e4ffbaa745a
parentc8e7a87b1ed6b00dc2c3543a80c892d5948f8849 (diff)
downloadllvm-931b6d51d84e2a5cbbdc925d546819d4d3b7c63e.tar.gz
Reenable POSIX builtin library functions in gnu2x mode
gnu17 and earlier modes automatically expose several POSIX C APIs, and this was accidentally disabled for gnu2x in 7d644e1215b376ec5e915df9ea2eeb56e2d94626. This restores the behavior for gnu2x mode (without changing the behavior in C standards modes instead of GNU modes). Fixes #56607
-rw-r--r--clang/docs/ReleaseNotes.rst4
-rw-r--r--clang/lib/Sema/SemaLookup.cpp8
-rw-r--r--clang/test/Sema/gnu-builtins.c13
3 files changed, 20 insertions, 5 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1ee8f0459ae..13cca2ebbfb8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@ Bug Fixes
`Issue 57377 <https://github.com/llvm/llvm-project/issues/57377>`_.
- Fix a crash when a ``btf_type_tag`` attribute is applied to the pointee of
a function pointer.
+- Clang 14 predeclared some builtin POSIX library functions in ``gnu2x`` mode,
+ and Clang 15 accidentally stopped predeclaring those functions in that
+ language mode. Clang 16 now predeclares those functions again. This fixes
+ `Issue 56607 <https://github.com/llvm/llvm-project/issues/56607>`_.
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 68158ec977cf..5d0d87fd2422 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -939,11 +939,9 @@ bool Sema::LookupBuiltin(LookupResult &R) {
// If this is a builtin on this (or all) targets, create the decl.
if (unsigned BuiltinID = II->getBuiltinID()) {
- // In C++, C2x, and OpenCL (spec v1.2 s6.9.f), we don't have any
- // predefined library functions like 'malloc'. Instead, we'll just
- // error.
- if ((getLangOpts().CPlusPlus || getLangOpts().OpenCL ||
- getLangOpts().C2x) &&
+ // In C++ and OpenCL (spec v1.2 s6.9.f), we don't have any predefined
+ // library functions like 'malloc'. Instead, we'll just error.
+ if ((getLangOpts().CPlusPlus || getLangOpts().OpenCL) &&
Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
return false;
diff --git a/clang/test/Sema/gnu-builtins.c b/clang/test/Sema/gnu-builtins.c
new file mode 100644
index 000000000000..c4da8b39363c
--- /dev/null
+++ b/clang/test/Sema/gnu-builtins.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=gnu -std=gnu17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=gnu -std=gnu2x %s
+// RUN: %clang_cc1 -fsyntax-only -verify=std -std=c17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=std -std=c2x %s
+
+// std-no-diagnostics
+
+// 'index' is a builtin library function, but only in GNU mode. So this should
+// give an error in GNU modes but be okay in non-GNU mode.
+// FIXME: the error is correct, but these notes are pretty awful.
+int index; // gnu-error {{redefinition of 'index' as different kind of symbol}} \
+ gnu-note {{unguarded header; consider using #ifdef guards or #pragma once}} \
+ gnu-note {{previous definition is here}}