Skip to content

Commit d7d7436

Browse files
committed
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 957eed0 commit d7d7436

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
@@ -274,6 +274,10 @@ Bug Fixes
274274
result in a stack overflow.
275275
`Issue 44304 <https://github.com/llvm/llvm-project/issues/44304>`_
276276
`Issue 50891 <https://github.com/llvm/llvm-project/issues/50891>`_
277+
- Clang 14 predeclared some builtin POSIX library functions in ``gnu2x`` mode,
278+
and Clang 15 accidentally stopped predeclaring those functions in that
279+
language mode. Clang 16 now predeclares those functions again. This fixes
280+
`Issue 56607 <https://github.com/llvm/llvm-project/issues/56607>`_.
277281

278282
Improvements to Clang's diagnostics
279283
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaLookup.cpp

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

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

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)