Bug 2005620 - libclang's clang_parseTranslationUnit() system include path seems to be wrong
Summary: libclang's clang_parseTranslationUnit() system include path seems to be wrong
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: clang
Version: 34
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Tom Stellard
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-09-18 18:08 UTC by Cristian Morales Vega
Modified: 2022-06-08 06:28 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-06-08 06:28:55 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Cristian Morales Vega 2021-09-18 18:08:32 UTC
Doxygen complains when using the clang parser when parsing a file with "#include <stdlib>" (https://github.com/doxygen/doxygen/issues/8783).

The problem seems to be in libclang. I'm not familiar with it, but I have come with this example code:

-------------
#include <clang-c/Index.h>
#include <iostream>

int main() {
  CXIndex index = clang_createIndex(0, 0);
  CXTranslationUnit unit = clang_parseTranslationUnit(
      index, "file.cpp", nullptr, 0, nullptr, 0, CXTranslationUnit_None);
  if (unit == nullptr) {
    std::cerr << "Unable to parse translation unit. Quitting." << std::endl;
    exit(1);
  }

  int n = clang_getNumDiagnostics(unit);
  for (int i = 0; i != n; ++i) {
    CXDiagnostic diag = clang_getDiagnostic(unit, i);
    CXString string =
        clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
    std::cout << clang_getCString(string) << std::endl;
    clang_disposeString(string);
    clang_disposeDiagnostic(diag);
  }

  clang_disposeTranslationUnit(unit);
  clang_disposeIndex(index);
}
-------------

Which prints "/usr/include/stdlib.h:31:10: fatal error: 'stddef.h' file not found" when looking at this file:

-------------
#include <stdlib.h>

int main() {}
-------------


With strace I see this is where it's looking for stddef.h
-------------
$ strace -f ./test 2>&1 | grep stddef
[pid  7191] openat(AT_FDCWD, "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  7191] openat(AT_FDCWD, "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/x86_64-redhat-linux/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  7191] openat(AT_FDCWD, "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/backward/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  7191] openat(AT_FDCWD, "/usr/local/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  7191] openat(AT_FDCWD, "/usr/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  7191] openat(AT_FDCWD, "/usr/include/sys/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
write(1, "/usr/include/stdlib.h:31:10: fat"..., 68/usr/include/stdlib.h:31:10: fatal error: 'stddef.h' file not found
-------------

And this is where it's installed
-------------
$ find /usr/ -name stddef.h
/usr/include/linux/stddef.h
/usr/include/c++/v1/stddef.h
/usr/lib/gcc/x86_64-redhat-linux/11/include/stddef.h
/usr/lib64/clang/12.0.1/include/stddef.h
-------------

Comment 1 Cristian Morales Vega 2021-09-19 19:52:57 UTC
To make it simpler, changing file.cpp for file.c, strace does this

-------------
$ strace -f ./test 2>&1 | grep stddef
[pid 26615] openat(AT_FDCWD, "/usr/local/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 26615] openat(AT_FDCWD, "/usr/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 26615] openat(AT_FDCWD, "/usr/include/sys/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
write(1, "/usr/include/stdlib.h:31:10: fat"..., 68/usr/include/stdlib.h:31:10: fatal error: 'stddef.h' file not found
-------------

Comment 2 Cristian Morales Vega 2021-09-19 20:20:34 UTC
And this is what happens in Ubuntu 21.04

-------------
root@012e96942e1c:/# strace -f ./la 2>&1 | grep stddef
[pid  4146] openat(AT_FDCWD, "/usr/local/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  4146] openat(AT_FDCWD, "lib/clang/12.0.0/include/stddef.h", O_RDONLY|O_CLOEXEC) = 3
[pid  4146] pread64(3, "/*===---- stddef.h - Basic type "..., 3589, 0) = 3589
-------------

Comment 3 Cristian Morales Vega 2021-09-20 17:14:25 UTC
There is https://bugs.llvm.org/show_bug.cgi?id=51914

Comment 4 Cristian Morales Vega 2021-09-22 12:43:37 UTC
Adding "-DCLANG_RESOURCE_DIR=%{pkg_libdir}/clang/%{version}" to the cmake invocation would seem to fix this issue (it's only using clang headers, not sure if it's supposed to be able to use the gcc ones), but that makes the RPM %check step fail.

Comment 5 Ben Cotton 2022-05-12 16:55:51 UTC
This message is a reminder that Fedora Linux 34 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 34 on 2022-06-07.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '34'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 34 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 6 Ben Cotton 2022-06-08 06:28:55 UTC
Fedora Linux 34 entered end-of-life (EOL) status on 2022-06-07.

Fedora Linux 34 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.