[libc-commits] [libc] [libc]: Clean up unnecessary function pointers in scanf (PR #121215)

Vinay Deshmukh via libc-commits libc-commits at lists.llvm.org
Sat Dec 28 08:54:51 PST 2024


vinay-deshmukh wrote:

<details>

<summary> Ubuntu error - linker error for read_unlocked ungetc_unlocked </summary>

```
usr/bin/ld: libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/./reader.cpp.o: in function `__llvm_libc_20_0_0_git::scanf_core::Reader::getc()':
reader.cpp:(.text._ZN22__llvm_libc_20_0_0_git10scanf_core6Reader4getcEv+0x38): undefined reference to `__llvm_libc_20_0_0_git::File::read_unlocked(void*, unsigned long)'
/usr/bin/ld: libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/./reader.cpp.o: in function `__llvm_libc_20_0_0_git::scanf_core::Reader::ungetc(char)':
reader.cpp:(.text._ZN22__llvm_libc_20_0_0_git10scanf_core6Reader6ungetcEc+0x2c): undefined reference to `__llvm_libc_20_0_0_git::File::ungetc_unlocked(int)'
/usr/bin/ld: libc/test/src/stdio/libc.test.src.stdio.vsscanf_test.__unit__.__build__: hidden symbol `_ZN22__llvm_libc_20_0_0_git4File13read_unlockedEPvm' isn't defined
/usr/bin/ld: final link failed: bad value
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
</details>


<details>
<summary> Windows error - macro substitution issue</summary>

```
[252/1389] Building CXX object libc\src\stdio\scanf_core\CMakeFiles\libc.src.stdio.scanf_core.reader.dir\reader.cpp.obj
FAILED: libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/reader.cpp.obj 
sccache C:\PROGRA~1\LLVM\bin\clang-cl.exe  /nologo -TP -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -ID:\a\llvm-project\llvm-project\libc -imsvcD:\a\llvm-project\llvm-project\build\libc\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Oi /Brepro /bigobj /permissive- -Werror=unguarded-availability-new /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O1 /Ob1 /DNDEBUG -std:c++17 -MD -Z7 -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS /EHs-c- /GR- /showIncludes /Folibc\src\stdio\scanf_core\CMakeFiles\libc.src.stdio.scanf_core.reader.dir\reader.cpp.obj /Fdlibc\src\stdio\scanf_core\CMakeFiles\libc.src.stdio.scanf_core.reader.dir\ -c -- D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp
In file included from D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp:10:
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(51,28): error: use of undeclared identifier 'off_t'
   51 |   using SeekFunc = ErrorOr<off_t>(File *, off_t, int);
      |                            ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(51,43): error: unknown type name 'off_t'
   51 |   using SeekFunc = ErrorOr<off_t>(File *, off_t, int);
      |                                           ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(87,3): error: unknown type name 'SeekFunc'
   87 |   SeekFunc *platform_seek;
      |   ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(90,3): error: unknown type name 'Mutex'
   90 |   Mutex mutex;
      |   ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(156,47): error: unknown type name 'SeekFunc'
  156 |   constexpr File(WriteFunc *wf, ReadFunc *rf, SeekFunc *sf, CloseFunc *cf,
      |                                               ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(186,21): error: unknown type name 'off_t'
  186 |   ErrorOr<int> seek(off_t offset, int whence);
      |                     ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(188,11): error: use of undeclared identifier 'off_t'
  188 |   ErrorOr<off_t> tell();
      |           ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(314,14): error: expected parameter declarator
  314 | extern File *stdin;
      |              ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.[261](https://github.com/llvm/llvm-project/actions/runs/12527517475/job/34941171823?pr=121215#step:10:262)00.0\ucrt\corecrt_wstdio.h(36,33): note: expanded from macro 'stdin'
   36 | #define stdin  (__acrt_iob_func(0))
      |                                 ^
In file included from D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp:10:
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(314,14): error: expected ')'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(36,33): note: expanded from macro 'stdin'
   36 | #define stdin  (__acrt_iob_func(0))
      |                                 ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(314,14): note: to match this '('
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(36,32): note: expanded from macro 'stdin'
   36 | #define stdin  (__acrt_iob_func(0))
      |                                ^
In file included from D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp:10:
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(315,14): error: expected parameter declarator
  315 | extern File *stdout;
      |              ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(37,33): note: expanded from macro 'stdout'
   37 | #define stdout (__acrt_iob_func(1))
      |                                 ^
In file included from D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp:10:
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(315,14): error: expected ')'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(37,33): note: expanded from macro 'stdout'
   37 | #define stdout (__acrt_iob_func(1))
      |                                 ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(315,14): note: to match this '('
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(37,32): note: expanded from macro 'stdout'
   37 | #define stdout (__acrt_iob_func(1))
      |                                ^
In file included from D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp:10:
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(316,14): error: expected parameter declarator
  316 | extern File *stderr;
      |              ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(38,33): note: expanded from macro 'stderr'
   38 | #define stderr (__acrt_iob_func(2))
      |                                 ^
In file included from D:\a\llvm-project\llvm-project\libc\src\stdio\scanf_core\reader.cpp:10:
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(316,14): error: expected ')'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(38,33): note: expanded from macro 'stderr'
   38 | #define stderr (__acrt_iob_func(2))
      |                                 ^
D:\a\llvm-project\llvm-project\libc\src/__support/File/file.h(316,14): note: to match this '('
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_wstdio.h(38,32): note: expanded from macro 'stderr'
   38 | #define stderr (__acrt_iob_func(2))
      |                                ^
13 errors generated.
```
</details>


<details>

<summary> Macos Error - macro substitution issue </summary>

```
libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/reader.cpp.o
FAILED: libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/reader.cpp.o 
sccache /usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -I/Users/runner/work/llvm-project/llvm-project/libc -isystem /Users/runner/work/llvm-project/llvm-project/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Os -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -MD -MT libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/reader.cpp.o -MF libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/reader.cpp.o.d -o libc/src/stdio/scanf_core/CMakeFiles/libc.src.stdio.scanf_core.reader.dir/reader.cpp.o -c /Users/runner/work/llvm-project/llvm-project/libc/src/stdio/scanf_core/reader.cpp
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/stdio/scanf_core/reader.cpp:10:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:90:3: error: unknown type name 'Mutex'
  Mutex mutex;
  ^
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected member name or ';' after declaration specifiers
  void clearerr_unlocked() { err = false; }
  ~~~~ ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:26: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                          ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/stdio/scanf_core/reader.cpp:10:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected ')'
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:26: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                          ^
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: note: to match this '('
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:25: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                         ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/stdio/scanf_core/reader.cpp:10:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: unknown type name '_flags'
  void clearerr_unlocked() { err = false; }
       ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:37: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                                     ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/stdio/scanf_core/reader.cpp:10:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:[260](https://github.com/llvm/llvm-project/actions/runs/12527517475/job/34941171892?pr=121215#step:10:261):8: error: a type specifier is required for all declarations
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:34: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                                  ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/stdio/scanf_core/reader.cpp:10:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected ')'
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:44: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                                            ^
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: note: to match this '('
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:397:30: note: expanded from macro 'clearerr_unlocked'
#define clearerr_unlocked(p)    __sclearerr(p)
                                ^
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:285:31: note: expanded from macro '__sclearerr'
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                               ^
6 errors generated.
```

</details>

https://github.com/llvm/llvm-project/pull/121215


More information about the libc-commits mailing list