This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix segmentation fault when formatting nested namespaces
ClosedPublic

Authored by d0nc1h0t on Aug 20 2023, 7:17 AM.

Details

Summary

Fixing the clang-format crash with the segmentation fault error when formatting code with nested namespaces.

Fixes: #64701

Diff Detail

Event Timeline

d0nc1h0t created this revision.Aug 20 2023, 7:17 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 20 2023, 7:17 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please try to ensure all code changes have a unit test (unless this is an NFC or refactoring, adding documentation etc..)

Add your unit tests in clang/unittests/Format and you can build with ninja FormatTests. We recommend using the verifyFormat(xxx) format of unit tests rather than EXPECT_EQ as this will ensure you change is tolerant to random whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can happen if you are trying to improve the annotation phase to ensure we are correctly identifying the type of a token, please add a token annotator test in TokenAnnotatorTest.cpp

d0nc1h0t requested review of this revision.Aug 20 2023, 7:17 AM

Please upload the patch with the full context. And add a test case. (From your issue.)

d0nc1h0t updated this revision to Diff 552281.Aug 22 2023, 2:59 AM

Added unittest.

Please upload the patch with the full context.

I'm creating a patch via 'git diff' from the root of the project. What does full context mean?

d0nc1h0t edited the summary of this revision. (Show Details)Aug 22 2023, 3:31 AM

Please upload the patch with the full context.

I'm creating a patch via 'git diff' from the root of the project. What does full context mean?

If you look at your diff here there is Context not available.. Please use git diff -U99999.

d0nc1h0t updated this revision to Diff 552604.Aug 22 2023, 11:39 PM

Updated the patch with full context.

owenpan added inline comments.Aug 23 2023, 2:49 AM
clang/lib/Format/UnwrappedLineFormatter.cpp
389–390

See below.

392–396

Or similar.

clang/unittests/Format/FormatTest.cpp
4187–4194

It seems that we can reduce the test case.

d0nc1h0t accepted this revision.Aug 23 2023, 3:20 AM
d0nc1h0t marked 3 inline comments as done.
This revision is now accepted and ready to land.Aug 23 2023, 3:20 AM
owenpan requested changes to this revision.Aug 23 2023, 11:25 AM

It seems that you forgot to update the diff?

This revision now requires changes to proceed.Aug 23 2023, 11:25 AM
d0nc1h0t updated this revision to Diff 553017.Aug 24 2023, 12:18 AM
owenpan accepted this revision.Aug 24 2023, 1:05 AM
owenpan added inline comments.
clang/lib/Format/UnwrappedLineFormatter.cpp
389–390

I forgot to suggest const.

clang/unittests/Format/FormatTest.cpp
4188–4191

Did you run git-clang-format?

This revision is now accepted and ready to land.Aug 24 2023, 1:05 AM
d0nc1h0t updated this revision to Diff 553085.Aug 24 2023, 5:40 AM

Added missing const + clang-format.

d0nc1h0t marked an inline comment as done.Aug 24 2023, 5:46 AM

Fixed. (Relied on auto-formatting in the IDE)

'git push' or 'arc land' give an error 'remote: Permission to llvm/llvm-project.git denied to d0nc1h0t'.
On an empty folder I tried

git clone https://github.com/llvm/llvm-project.git/ .
arc patch D158363
arc land

with the same error. Maybe there are not enough rights to the project on GitHub?

We need the name and email you want to use in order to commit the patch for you.

We need the name and email you want to use in order to commit the patch for you.

Arkadiy Yudintsev <udincev@yandex.ru>