Skip to content

Commit 931b6d5

Browse files
AaronBallmantstellar
authored andcommitted
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 7d644e1. This restores the behavior for gnu2x mode (without changing the behavior in C standards modes instead of GNU modes). Fixes #56607
1 parent c8e7a87 commit 931b6d5

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ Bug Fixes
227227
`Issue 57377 <https://github.com/llvm/llvm-project/issues/57377>`_.
228228
- Fix a crash when a ``btf_type_tag`` attribute is applied to the pointee of
229229
a function pointer.
230+
- Clang 14 predeclared some builtin POSIX library functions in ``gnu2x`` mode,
231+
and Clang 15 accidentally stopped predeclaring those functions in that
232+
language mode. Clang 16 now predeclares those functions again. This fixes
233+
`Issue 56607 <https://github.com/llvm/llvm-project/issues/56607>`_.
230234

231235
Improvements to Clang's diagnostics
232236
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaLookup.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -939,11 +939,9 @@ bool Sema::LookupBuiltin(LookupResult &R) {
939939

940940
// If this is a builtin on this (or all) targets, create the decl.
941941
if (unsigned BuiltinID = II->getBuiltinID()) {
942-
// In C++, C2x, and OpenCL (spec v1.2 s6.9.f), we don't have any
943-
// predefined library functions like 'malloc'. Instead, we'll just
944-
// error.
945-
if ((getLangOpts().CPlusPlus || getLangOpts().OpenCL ||
946-
getLangOpts().C2x) &&
942+
// In C++ and OpenCL (spec v1.2 s6.9.f), we don't have any predefined
943+
// library functions like 'malloc'. Instead, we'll just error.
944+
if ((getLangOpts().CPlusPlus || getLangOpts().OpenCL) &&
947945
Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
948946
return false;
949947

clang/test/Sema/gnu-builtins.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify=gnu -std=gnu17 %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify=gnu -std=gnu2x %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify=std -std=c17 %s
4+
// RUN: %clang_cc1 -fsyntax-only -verify=std -std=c2x %s
5+
6+
// std-no-diagnostics
7+
8+
// 'index' is a builtin library function, but only in GNU mode. So this should
9+
// give an error in GNU modes but be okay in non-GNU mode.
10+
// FIXME: the error is correct, but these notes are pretty awful.
11+
int index; // gnu-error {{redefinition of 'index' as different kind of symbol}} \
12+
gnu-note {{unguarded header; consider using #ifdef guards or #pragma once}} \
13+
gnu-note {{previous definition is here}}

0 commit comments

Comments
 (0)