This is an archive of the discontinued LLVM Phabricator instance.

Respect "-fdiagnostics-absolute-paths" on emit include location
ClosedPublic

Authored by charmitro on May 31 2023, 12:58 PM.

Details

Summary

This commit fixes "TextDiagnostic::emitIncludeLocation" when compiling
with "-fdiagnostics-absolute-paths" flag enabled by emitting the absolute
path of the included file.

Fixes #63026

Diff Detail

Event Timeline

charmitro created this revision.May 31 2023, 12:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 12:58 PM
charmitro requested review of this revision.May 31 2023, 12:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 12:58 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
charmitro edited the summary of this revision. (Show Details)May 31 2023, 1:02 PM

Can you add a test case for the change? Looks like there's something similar already in clang/test/Frontend/absolute-paths.c

Can you add a test case for the change? Looks like there's something similar already in clang/test/Frontend/absolute-paths.c

Is it possible to use substitutions inside let's say NORMAL: ? How could I resolve the absolute path without hard-coding my path inside the test case?

charmitro updated this revision to Diff 527821.Jun 2 2023, 5:36 AM

Can you add a test case for the change? Looks like there's something similar already in clang/test/Frontend/absolute-paths.c

Is it possible to use substitutions inside let's say NORMAL: ? How could I resolve the absolute path without hard-coding my path inside the test case?

I was able to make it work using -DNAME=<value> in the FileCheck invocation inside absolute-paths.c test file.

charmitro updated this revision to Diff 527828.Jun 2 2023, 6:01 AM
tbaeder added inline comments.Jun 2 2023, 6:16 AM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

This checks the same thing in both cases, but in the NORMAL case, it should not use the absolute path, shouldn't it?

charmitro added inline comments.Jun 2 2023, 6:50 AM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

You're correct. I was constantly testing it from the same path.

Since the relative path is going to be different depending on where you running from, would it be wise to accept a regular expression of any string in the NORMAL case?

For example,

NORMAL: In file included from {{.*}}:
tbaeder added inline comments.Jun 2 2023, 7:56 AM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

I wonder if it would make sense to just check for the filename in the NORMAL case and then do a NORMAL-NOT: [[ROOT_ABSOLUTE]]?

charmitro added inline comments.Jun 2 2023, 8:05 AM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

Yes, that way we are testing if the warning contains the correct filename+LOC.

Something like: // NORMAL: In file included from {{.*absolute-paths.c:4}}:.

But why changefrom ABSOLUTE: to NORMAL-NOT?

charmitro updated this revision to Diff 527914.Jun 2 2023, 11:11 AM
tbaeder added inline comments.Jun 2 2023, 10:39 PM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

Your regex checks if the path ends with the file name, right? That would be true in both cases.

charmitro added inline comments.Jun 3 2023, 3:14 AM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

What else do you propose here?

Let me explain why this was the only obvious option for me.

In the case of NORMAL, it checks for the relative path based on the location you invoke the test commands.

Given that, if we, for example,

  1. run llvm-lit from the project root, the NORMAL case expects:
In file included from clang/test/Frontend/absolute-paths.c:4:
  1. run llvm-lit from $PROJECT_ROOT/clang/test/, the NORMAL case expects:
In file included from Frontend/absolute-paths.c:4:

It seems unwise to me to hard-code the path based on what the CI excepts in the NORMAL scenario, because that way, whoever runs the test cases manually, will experience test failure.

tbaeder added inline comments.Jun 3 2023, 10:24 PM
clang/test/Frontend/absolute-paths.c
6 ↗(On Diff #527828)

You can still keep the ABSOLUTE: [[ROOT_ABSOLUTE]] stuff, I was just proposing to add the NORMAL-NOT one additionally, so we can make sure we're not printing the absolute path in the normal case as well.

charmitro updated this revision to Diff 528219.Jun 4 2023, 8:23 AM

LGTM, but maybe wait for a response from @aaron.ballman or @cjdb

This revision is now accepted and ready to land.Jun 5 2023, 7:51 AM

Do you need someone to commit on your behalf? If so, what name and email address would you like used for patch attribution?

@charmitro do you have commit rights or do you need someone to push on your behalf?

charmitro marked an inline comment as done.Jun 5 2023, 8:14 AM

Do you need someone to commit on your behalf? If so, what name and email address would you like used for patch attribution?

@charmitro do you have commit rights or do you need someone to push on your behalf?

I do not have commit rights, since I'm planning to contribute more often, I'd like commit access at some point. I can request it ASAP if needed.

cjdb added a comment.Jun 5 2023, 9:28 AM

Can the commit message have a description please? It's unclear to me why this is necessary (although I'm sure there's a good reason).

charmitro edited the summary of this revision. (Show Details)Jun 5 2023, 10:13 AM

Can the commit message have a description please? It's unclear to me why this is necessary (although I'm sure there's a good reason).

Thanks! Done, also check https://github.com/llvm/llvm-project/issues/63026

cjdb added a comment.Jun 5 2023, 10:23 AM

Can the commit message have a description please? It's unclear to me why this is necessary (although I'm sure there's a good reason).

Thanks! Done, also check https://github.com/llvm/llvm-project/issues/63026

Nice, thanks! Would you mind adding Fixes #63026. somewhere in the commit message? That will auto-close the issue upon merge.

charmitro edited the summary of this revision. (Show Details)Jun 5 2023, 10:24 AM

Can the commit message have a description please? It's unclear to me why this is necessary (although I'm sure there's a good reason).

Thanks! Done, also check https://github.com/llvm/llvm-project/issues/63026

Nice, thanks! Would you mind adding Fixes #63026. somewhere in the commit message? That will auto-close the issue upon merge.

Thanks for pointing that, done.

Do you need someone to commit on your behalf? If so, what name and email address would you like used for patch attribution?

@charmitro do you have commit rights or do you need someone to push on your behalf?

I do not have commit rights, since I'm planning to contribute more often, I'd like commit access at some point. I can request it ASAP if needed.

Author should be:
Charalampos Mitrodimas <charmitro@gmail.com>

cjdb added a comment.Jun 5 2023, 10:38 AM

I already have another commit I plan to push, will do these together :)

This revision was automatically updated to reflect the committed changes.