[clang] [Serialization] Downgrade error to warning for inconsistent language flags (PR #117840)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 19:07:20 PST 2024


ChuanqiXu9 wrote:

> I see, so because we no longer allow inconsistent options when importing, we now issue a lot of error diagnostics. But for many of the options, differences between TUs should have no impact on modules anyway, and so those errors are false positives. Is that about correct?

Yes.

> If I'm right, then what about a different way forward: update the individual options to specify whether it is an error, a warning, or silently fine for the option to be inconsistent across module boundaries, the emit diagnostics (or not) as appropriate for each option. It's more up-front work, but it means we stop issue false positive errors without losing diagnostic fidelity. (Note, we may find we want to reorganize Options.td so it's easier for us to specify "this entire block of options are ones for which module inconsistency is an error".)

The problem may be about the amount of work. Although I am not sure how far we can make it in practice, it is technically doable.

---

Some other thoughts about false-positive error diagnostics. I am wondering, if we don't want false-positive error diagnostics at all, then we have to do what I proposed in this PR (to downgrade errors to warnings for inconsistent flags). Otherwise, we can always construct at least one example that it is false-positive to diagnose the inconsistency. e.g.,

```
/// m1.cppm
export module m1;
// eof

// m2.cpp
import m1;
```

then is it really matter to compile `m1.cppm` with `-std=c++23` and import it to `m2.cpp` which is compiled as `-std=c++20`? I don't think so as far as I know. So is it a false-positive error diagnostic? I think yes. And `-std=` may be the most impactful options, if we can construct cases for `-std=`, then we can construct cases for other flags too. Then, if we can't tolerant false positive error diagnostics, we should emit warnings instead for all the flags.











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


More information about the cfe-commits mailing list