[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67360)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 26 11:41:16 PDT 2023


AaronBallman wrote:

There are six failures I've found, three in tests and three in source:

Source:
* https://github.com/llvm/llvm-project/blob/ebfea261e6a28e0ba33f437476202a25212b2d34/compiler-rt/lib/fuzzer/afl/afl_driver.cpp#L112
* https://github.com/llvm/llvm-project/blob/ebfea261e6a28e0ba33f437476202a25212b2d34/compiler-rt/lib/builtins/cpu_model.c#L30
* https://github.com/llvm/llvm-project/blob/ebfea261e6a28e0ba33f437476202a25212b2d34/compiler-rt/lib/profile/GCDAProfiling.c#L560

Tests:
* https://github.com/llvm/llvm-project/blob/ebfea261e6a28e0ba33f437476202a25212b2d34/compiler-rt/test/ubsan/TestCases/Misc/Linux/sigaction.cpp#L14
* https://github.com/llvm/llvm-project/blob/ebfea261e6a28e0ba33f437476202a25212b2d34/compiler-rt/test/profile/Posix/gcov-destructor.c#L24
* https://github.com/llvm/llvm-project/blob/43d2ef2856fc3373068c020efa11a933477e11fa/libc/test/integration/startup/gpu/init_fini_array_test.cpp#L51

In each case, the failure is due to using a reserved priority. There are two (or more) ways to address this without changing priorities: 1) use line markers around the code using the problematic priorities, 2) downgrade the priority diagnostic from an error to a warning. GCC currently has `-Wprio-ctor-dtor` and treats the priority issue as a warning rather than an error. I don't like that approach because 1) warnings are trivial to ignore and so the reservation has no teeth, 2) the name of the warning group is startlingly bad. 3) `init_priority` has the same reservation as `constructor` and `destructor` and that's been an error in Clang since at least 3.0.

However, it's not clear to me what compiler-rt folks think (they're the ones predominately impacted). CC @MaskRay for more opinions on whether I should use line markers or downgrade the diagnostic. One potential option would be to have this as a warning which defaults to an error, but my preference is to try to retain it as a hard error if possible so that the reservation is meaningful.

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


More information about the cfe-commits mailing list