This is needed for CUDA compilation where NVPTX back-end only supports DWARF2,
but host compilation should be allowed to use newer DWARF versions.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/include/clang/Driver/ToolChain.h | ||
---|---|---|
496 | Given these semantics (pass/return the version) maybe "AdjustDwarfVersion" or the like might be more suitable (are there other similar functions in this API That can/do this sort of pass/return API?). Alternatively, a narrower/simpler API could be "GetMaxDwarfVersion", say, which just returns int_max by default and 2 for NVPTX? | |
clang/lib/Driver/ToolChains/Clang.cpp | ||
3848 | I worry a bit about having both DWARFVersion and AdjustedDwarfVersion in this scope (I'd worry about some codepaths using one when they needed to use the other, etc) - if at all possible, would be good to just override DWARFVersion with the adjusted value. And probably could/should be up in the "EmitDwarf" block above that's handling default dwarf versions and overrides of it? |
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
3848 | Ive updated the implementation to make it less ambiguous. PTAL. |
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
3948 | I think, ideally, the DWARFVersion calculation would happen up if (EmitDwarf) { block where all default and explicit dwarf version calculations are done. I guess it's not done that way because of the gembed-source error path? |
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
3948 | That's part of it. -gembed-source does need to know both the specified DWARF version and the clamped one. I could move the calculation of the effective DWARF version back to where it was in the first version of the patch, and we'll need both the specified and the clamped values. As for moving it under if( EmitDwarf), the problem is that the DWARF version also affects cases when EmitDwarf is false, so the clamping needs to be done regardless. E.g. the -gmlt option that was used in our build break that uncovered the issue. We do not emit DWARF per se, but the DefaultDWARFVersion does affect the generation of the lineinfo debugging and we do need to clamp it. |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
---|---|---|
2 | A NOT pattern may easily become stale and do not actually check anything. Just turn to a positive pattern? |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
---|---|---|
2 | In this case the issue is with the CHECK-NOT line above. I'll have to replicate it around the positive match of -dwarf-version which would raise more questions. I wish filecheck would allow to mark a region and then run multiple matches on it, instead of re-anchoring on each match. |
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
3948 | Is the warning necessary? Could we let -gembed-source be an error if you're targeting NVPTX? (I realize that goes a bit against the idea of this patch, which is to keep DWARFv2 even when you've got a bunch of DWARFv5 flags that you presumably want for the rest of your builds) Or, I guess another option, might be to make -gembed-source a warning for non-v5 DWARF in general, instead of an error, then the implementation could be generic. What I'd really like is for the DWARFVersion to be computed as compactly as possible without the concept of multiple versions leaking out as much as possible.
That doesn't sound right to me, -gmlt qualifies as "emitting DWARF" and at least a quick/simple debug through the driver for "clang x.cpp -gmlt" does seem to lead to "EmitDwarf" being true and the block at line 3841 being reached. EmitDwarf is set to true in that case at 3834 because DebugInfoKind is not NoDebugInfo (it's DebugLineTablesOnly) |
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
3948 |
I think the warning is the sensible thing to do here. Making it an error would effectively make it impossible to use it on the host side of the compilation where it's perfectly fine and where it's most useful.
That would work. Then we'll only need the capped dwarf version and that could be moved upward. I've updated the patch. PTAL.
You are correct. Even when we only emit debug info via .loc, EmitDwarf is set. |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
---|---|---|
2 | Sounds like you're looking for CHECK-DAG, maybe? ( https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-dag-directive ) | |
clang/test/Driver/debug-options.c | ||
364–366 ↗ | (On Diff #309585) | This is a bit of a loss in fidelity - might need a new diagnostic message (or go hunting around for a more general purpose one than this one at least) to say '-gembed-source' is ignored when not using DWARFv5. (in the nvptx case it's "not supported on target", but in the existing cases covered by this test it's "not supported because the user requested DWARFv2", for instance) @JDevlieghere & @scott.linder for thoughts on this. |
clang/test/Driver/debug-options.c | ||
---|---|---|
364–366 ↗ | (On Diff #309585) | I agree that I'd prefer we detect whether the target-specific clamped version is to blame (and use the proposed warning message) or the original DWARF version is to blame (and use the old message). If I were compiling for x86 and gave e.g. -gdwarf-4 -gembed-source and the error said "not supported by target" I'd probably get the wrong idea. It would also be nice to retain the error semantics in the case where the user is explicitly requesting incompatible options. |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
---|---|---|
2 | I don't think CHECK-DAG can be mixed with CHECK-NOT. At least, not the way I need them here. From FileCheck docs:
So, in order to use it here I'll need something like this: // CHECK: -triple // GPU-side compilation // CHECK-NOT: {{all unsupported options}} // CHECK: -dwarf-version=2 // Could be CHECK-DAG, too, it does not matter in this case. // We have to repeat the NOT check here because the positive check above creates another subset of input to check for -NOT. // CHECK-NOT: {{all unsupported options}} // CHECK: - triple // Host-side compilation Ideally I want something like this: // CHECK-WITHOUT-ADVANCE: -dwarf-version=2 // CHECK-NOT: {{unsupported options}} If you prefer positive check with replicated -NOT, I'm fine with that. | |
clang/test/Driver/debug-options.c | ||
364–366 ↗ | (On Diff #309585) | This sounds pretty close to what the older iterations of this patch did: https://reviews.llvm.org/D92617?id=309404, except that it preserved the current behavior which makes it an error to use -gembed-source with an explicitly specified DWARF version below 5. Same options with a lower clamped version produces a warning. I.e. If user specified a nominally valid combination of -gdwarf-5 -gembed-source but the target like NVPTX clamped it down to DWARF2, there will only be a warning. I would appreciate if you (as in debug info stakeholders) could clarify couple of moments for me:
|
clang/test/Driver/debug-options.c | ||
---|---|---|
364–366 ↗ | (On Diff #309585) |
I think it should remain an error when an incompatible DWARF version is explicitly specified by the user. They said they wanted two things which are mutually exclusive, and we have no way to know which one they meant (or if they just aren't aware they are incompatible) so we should stop and prompt them to fix it.
I think giving more context is a good thing in this situation; I don't know that I have a strong opinion on the wording, but something indicating the warning is due to a target restriction which caps the DWARF version seems helpful enough to warrant being more verbose. I'd vote for your because target only supports DWARF <N> |
clang/test/Driver/debug-options.c | ||
---|---|---|
364–366 ↗ | (On Diff #309585) | OK, sounds like we're going mostly back towards the originally proposed code. Fair enough - if that's the case I'd make one suggestion to tweak the original code: Rather than keeping DWARFVersion unclamped and having AdjustedDWARFVersion as well - It might work better to have DWARFVersion updated correctly (in the "if (EmitDwarf)" block) and save "UnadjustedDWARFVersion" (open to other naming suggestions) so that vaule can be consulted later to determine the appropriate error or warning to be emitted. But this way "DWARFVersion" does carry the to-be-emitted DWARF version which is more likely what the next developer to touch this code will be thinking about/wanting when they reach for that variable. |
clang/include/clang/Basic/DiagnosticDriverKinds.td | ||
---|---|---|
296 | Probably worth testing the rest of this error message to check the versions and target names all show up as intended (looks like the test currently glosses over the differences between this warning and the other error?) - and also testing that it's emitted as a warning, whereas the other/pre-existing diagnostic was emitted as an error (oh, I guess perhaps it already is, just in another file - could you check that it is tested narrowly/ensured it's an error elsewhere?) | |
clang/lib/Driver/ToolChains/Clang.cpp | ||
3920–3921 | Use "else if {" on one line here, perhaps? |
clang/include/clang/Basic/DiagnosticDriverKinds.td | ||
---|---|---|
296 |
Done.
The error case is already tested in https://github.com/llvm-mirror/clang/blob/master/test/Driver/debug-options.c#L355 | |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
1 | The wildcard eats the differences between two warnings -- a generic one:
and the more specific one for -gembed-source :
| |
clang/test/Driver/openmp-unsupported-debug-options.c | ||
0 | Yes, same here. |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
---|---|---|
1 | Is that necessary? Or is the -gembed-source+CHECK test redundant with/less precise than the -gembed-source+DWARF-CLAMP test? (ie: would it be effective (not a loss in test coverage) to remove the gembed-source+CHECK test and only have the gembed-source+DWARF-CLAMP test, and keep the CHECK line precise as it was before for all the CHECK tests) Effectively: Rather than adding a new RUN line, and generalizing the CHECK over the new/old message and checking the new message separately - instead, change the existing gembed-source test to use DWARF-CLAMP instead of CHECK, and leave everything the same? |
clang/test/Driver/cuda-unsupported-debug-options.cu | ||
---|---|---|
1 | CHECK lines test that an option was ignored for the right target (nvptx, not x86). So, both warning variants should participate. DWARF-CLAMP verify that the correct DWARF version was used. -gembed-source shoud participate in both tests. The options here is to either include -gembed-source in the CHECK tests and make it accept both pattern variants, or replicate the target of the warning check within DWARF-CLAMP. I would prefer to keep these two kinds of tests separate. I've just updated the patch and moved DWARF clamping tests into a separate file and consolidated nearly-identical cuda/omp unsupported option warnings tests into the same file. |
Probably worth testing the rest of this error message to check the versions and target names all show up as intended (looks like the test currently glosses over the differences between this warning and the other error?) - and also testing that it's emitted as a warning, whereas the other/pre-existing diagnostic was emitted as an error (oh, I guess perhaps it already is, just in another file - could you check that it is tested narrowly/ensured it's an error elsewhere?)