This is an archive of the discontinued LLVM Phabricator instance.

Headers: fix collisions with .h files of other projects
Needs ReviewPublic

Authored by andrewrk on Aug 25 2018, 7:44 PM.

Details

Summary

stdarg.h:

  • va_list - macos _va_list.h was duplicately defining va_list. Fixed by this ifndef _VA_LIST_T
  • additionally define _VA_LIST_DEFINED because glibc stdio.h was duplicately defining va_list

stddef.h

  • ptrdiff_t - wrap in _PTRDIFF_T_DEFINED to protect against mingw defining it twice
  • size_t - protections against collisions with mingw
  • wchar_t - protections against duplicate definition with mingw

All of these came up in real world scenarios when using libclang to parse .h files in the Zig project.
These are the patches that Zig has on top of libclang headers, and if this patch is merged, then
Zig project will be tracking clang trunk.

Diff Detail

Repository
rC Clang

Event Timeline

andrewrk created this revision.Aug 25 2018, 7:44 PM
Qix- added a subscriber: Qix-.Aug 25 2018, 8:10 PM
Qix- added inline comments.
lib/Headers/stdarg.h
30

Super nit-picky but you could condense this a bit by using

#if !defined(_VA_LIST) && !defined(_VA_LIST_T)

and a single #endif (revert the addition of line 34).

It's arguably easier to understand intent instead of adding another level of nesting. Same thing goes for the other two sections.

Just a suggestion.

andrewrk updated this revision to Diff 162574.Aug 25 2018, 8:24 PM

Addressed review feedback

efriedma added a subscriber: efriedma.

What is this change actually solving? Even if the typedef is actually redundant, it shouldn't cause a compiler error: redundant typedefs are allowed in the latest versions of the C and C++ standards. (And even if you were targeting an earlier standard, we normally suppress warnings in system headers.)

andrewrk marked an inline comment as done.Aug 27 2018, 8:50 PM

What is this change actually solving? Even if the typedef is actually redundant, it shouldn't cause a compiler error: redundant typedefs are allowed in the latest versions of the C and C++ standards. (And even if you were targeting an earlier standard, we normally suppress warnings in system headers.)

Here's an example use case that this solves:

  • Install MXE (See https://mxe.cc/)
  • Install the png package
  • Use libclang API to parse png.h
  • Expect that there are no errors, but there are errors

Can you give the text of the error messages?

If you're seeing a "typedef redefinition with different types" error, libclang is getting confused about the target. And parsing code for the wrong target cannot work in general.