llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang doesn't include two headers symlinked to the same target

Open karen-arutyunov opened this issue 7 years ago • 1 comments

Bugzilla Link 42500
Version 6.0
OS Linux
Attachments Test program
CC @zygoloid

Extended Description

Hello,

My system is Fedora 28 with clang 6.0.1 installed as the clang-6.0.1-2.fc28.x86_64 package.

When compiling a C source file that includes two headers which are different symlinks to the same target, then the second header is not included.

The issue is reproduced by the attached test program:

$ tar xfz test.tar.gz $ cd test

$ tree --charset ascii . |-- a | |-- linux.h | -- platform.h -> ../platform.h |-- b | |-- linux.h | -- platform.h -> ../platform.h |-- main.c `-- platform.h

$ clang -I. main.c main.c:8:7: error: use of undeclared identifier 'B' r = B; ^ 1 error generated.

The only explanation why the macro B is not defined is that the header b/platform.h is not included.

Note that gcc compiles with no errors:

$ gcc -I. main.c $ ls a.out a.out

Also note that if to replace the b/platform.h symlink with its target then clang compiles with no errors either:

$ rm a.out b/platform.h $ cp platform.h b/ $ clang -I. main.c $ ls a.out a.out

karen-arutyunov avatar Jul 03 '19 18:07 karen-arutyunov

Hi, this behavior is no longer observed on trunk and this issue can be closed.

hkumar@:/data/hkumar/test/header_symlinked/test$ cat main.c
#include "a/platform.h"
#include "b/platform.h"
#include <stdio.h>

int
main ()
{
  int r = A;
  printf("%d", r);
  r = B;
  printf("%d", r);

  return r;
}
hkumar:/data/hkumar/test/header_symlinked/test$ ls
a  a.out  b  main.c  platform.h
hkumar:/data/hkumar/test/header_symlinked/test$ clang -I. main.c
hkumar:/data/hkumar/test/header_symlinked/test$ ./a.out
12
hkumar:/data/hkumar/test/header_symlinked/test$

mahtohappy avatar Feb 15 '24 10:02 mahtohappy