This is an archive of the discontinued LLVM Phabricator instance.

[NFCI][mlir][Tests] Rename identifiers minor/major to avoid clashes with system headers
ClosedPublic

Authored by rogfer01 on Jul 31 2023, 5:46 AM.

Details

Summary

Identifiers major and minor are often already taken in POSIX systems due to their presence in <sys/types.h> as part of the makedev library function.

Recent versions of glibc have moved this definitions from <sys/types.h> to sys/sysmacros.h, so newer systems may not be impacted. From the Linux link above:

Depending on the version, glibc also exposes definitions for these macros from <sys/types.h> if suitable feature test macros are defined. However, this behavior was deprecated in glibc 2.25, and since glibc 2.28, <sys/types.h> no longer provides these definitions.

In particular Ubuntu 18.04 LTS (albeit a bit old now) still provides them in <sys/types.h> along with a loud warning. Ubuntu 22.04 LTS does not have this problem. I have not been able to test it on 20.04 LTS.

Other systems, such as FreeBSD still use <sys/types.h> so there is not much we can do I think. I have verified that the issue happens on a VM running FreeBSD 13.2.

I initially considered doing:

#if defined(major)
#undef major
#endif
#if defined(minor)
#undef minor
#endif

but on a second thought I preferred the longer route of avoiding those identifiers entirely.

Diff Detail

Event Timeline

rogfer01 created this revision.Jul 31 2023, 5:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2023, 5:46 AM
rogfer01 requested review of this revision.Jul 31 2023, 5:46 AM
mfrancio accepted this revision.Jul 31 2023, 7:17 AM
mfrancio added inline comments.
mlir/test/lib/Dialect/Test/TestDialect.h
68–74

nit: camel case

70

Can we add a comment explaining the name clash here?

This revision is now accepted and ready to land.Jul 31 2023, 7:17 AM
rogfer01 updated this revision to Diff 545647.Jul 31 2023, 7:28 AM

ChangeLog:

  • Address review comments
rogfer01 marked 2 inline comments as done.Jul 31 2023, 7:28 AM
This revision was landed with ongoing or failed builds.Jul 31 2023, 7:37 AM
This revision was automatically updated to reflect the committed changes.