This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro
ClosedPublic

Authored by jspam on Jun 20 2022, 12:10 AM.

Details

Summary

Check llvm::Optional before dereferencing it.

Compute VirtualEndLoc differently to avoid an assertion failure
in clang::SourceManager::getFileIDLoaded:

Assertion `0 && "Invalid SLocOffset or bad function choice"' failed

Diff Detail

Event Timeline

jspam created this revision.Jun 20 2022, 12:10 AM
jspam requested review of this revision.Jun 20 2022, 12:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 12:10 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jspam retitled this revision from cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro to [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro.Jun 20 2022, 12:12 AM
LegalizeAdulthood requested changes to this revision.EditedJun 22 2022, 1:59 PM

Please rebase this and fold your changes into checkers/cppcoreguidelines/virtual-class-destructor.cpp

This revision now requires changes to proceed.Jun 22 2022, 1:59 PM
jspam updated this revision to Diff 439300.Jun 23 2022, 2:53 AM

Rebased

jspam added a comment.Jun 23 2022, 9:19 AM

@LegalizeAdulthood Not sure what exactly you mean by "fold your changes into checkers/cppcoreguidelines/virtual-class-destructor.cpp". The only rebase conflict was in VirtualClassDestructorCheck.cpp. Please let me know if there is still something to do.

@LegalizeAdulthood Not sure what exactly you mean by "fold your changes into checkers/cppcoreguidelines/virtual-class-destructor.cpp". The only rebase conflict was in VirtualClassDestructorCheck.cpp. Please let me know if there is still something to do.

Clang-Tidy tests and docs have moved to module subdirectories. You had originally edited the file checkers/cppcoreguidelines-virtual-class-destructor.cpp (no subdirectory, file named with module prefix) and this file was moved to checkers/cppcoreguidelines/virtual-class-destructor.cpp (now in a module subdirectory, no module prefix in file name).

Looks like git handled it automatically and you didn't notice :). This is good because it means I did the "right git thing" when I moved/renamed the files and that for most people, simply rebasing should be enough to ensure that their changes are following the file to the new location.

This revision is now accepted and ready to land.Jun 23 2022, 10:51 AM

I see :) Yes, looks like Git's rename detection did its job.

Thanks for the review. Could you or someone else please merge this for me? Author: Joachim Priesner <llvm-project-704996@jspam.de>

I see :) Yes, looks like Git's rename detection did its job.

Thanks for the review. Could you or someone else please merge this for me? Author: Joachim Priesner <llvm-project-704996@jspam.de>

I can submit, yes.

LegalizeAdulthood requested changes to this revision.Jun 24 2022, 11:17 AM

I get a test failure when I run with your change:

  -- Testing: 972 tests, 12 workers --
  FAIL: Clang Tools :: clang-apply-replacements/basic.cpp (680 of 972)
  ******************** TEST 'Clang Tools :: clang-apply-replacements/basic.cpp' FAILED ********************
  Script:
  --
  : 'RUN: at line 1';   mkdir -p D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
  : 'RUN: at line 2';   grep -Ev "// *[A-Z-]+:" D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h > D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h
  : 'RUN: at line 3';   sed "s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#" D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file1.yaml > D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/file1.yaml
  : 'RUN: at line 4';   sed "s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#" D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file2.yaml > D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/file2.yaml
  : 'RUN: at line 5';   clang-apply-replacements D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
  : 'RUN: at line 6';   FileCheck -input-file=D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h
  : 'RUN: at line 9';   ls -1 D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic | FileCheck D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp --check-prefix=YAML
  : 'RUN: at line 12';   grep -Ev "// *[A-Z-]+:" D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h > D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h
  : 'RUN: at line 13';   clang-apply-replacements -remove-change-desc-files D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
  : 'RUN: at line 14';   ls -1 D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic | FileCheck D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp --check-prefix=NO_YAML
  --
  Exit Code: 1

  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "mkdir" "-p" "D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
  $ ":" "RUN: at line 2"
  $ "grep" "-Ev" "// *[A-Z-]+:" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h"
  $ ":" "RUN: at line 3"
  $ "sed" "s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file1.yaml"
  $ ":" "RUN: at line 4"
  $ "sed" "s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file2.yaml"
  $ ":" "RUN: at line 5"
  $ "clang-apply-replacements" "D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
  $ ":" "RUN: at line 6"
  $ "FileCheck" "-input-file=D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h"
  $ ":" "RUN: at line 9"
  $ "ls" "-1" "D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
  $ "FileCheck" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp" "--check-prefix=YAML"
  $ ":" "RUN: at line 12"
  $ "grep" "-Ev" "// *[A-Z-]+:" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h"
  $ ":" "RUN: at line 13"
  $ "clang-apply-replacements" "-remove-change-desc-files" "D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
  $ ":" "RUN: at line 14"
  $ "ls" "-1" "D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
  $ "FileCheck" "D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp" "--check-prefix=NO_YAML"
  # command stderr:
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp(17,17): error G8807F445: NO_YAML-NOT: excluded string found in input [D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\check-clang-extra.vcxproj]
  // NO_YAML-NOT: {{^file.\.yaml$}}
                  ^
  <stdin>:2:1: note: found here
  file1.yaml
  ^~~~~~~~~~

  Input file: <stdin>
  Check file: D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp

  -dump-input=help explains the following input dump.

  Input was:
  <<<<<<
          1: basic.h
          2: file1.yaml
not : 17     !~~~~~~~~~ error : no match expected [D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\check-clang-extra.vcxproj]
  >>>>>>

CUSTOMBUILD : error : command failed with exit status: 1 [D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\check-clang-extra.vcxproj]

  --

  ********************
  ********************
  Failed Tests (1):
    Clang Tools :: clang-apply-replacements/basic.cpp


  Testing Time: 707.23s
    Unsupported      :   11
    Passed           : 1983
    Expectedly Failed:    2
    Failed           :    1
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(245,5): error MSB8066: Custom build for 'D:\legalize\llvm\llvm-project\build\CMakeFiles\5761a0d8e5ced254ad62b101e70e3dea\check-clang-extra.rule' exited with code 1. [D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\check-clang-extra.vcxproj]

If I revert your change, then the tests pass.... can you take a look? Build the CMake target check-clang-extra

This revision now requires changes to proceed.Jun 24 2022, 11:17 AM

Well, it must have been unrelated to your change or some weird interaction on my machine because I rebased and ran check-clang-extra again and it passed this time.

This revision is now accepted and ready to land.Jun 25 2022, 2:49 PM

I pushed this change, but for some reason phabricator doesn't show it and close the review... I wonder if it's because I rebased it?

jspam closed this revision.Jun 27 2022, 9:48 AM

No idea, I'll just close this then :)

myhsu added a subscriber: myhsu.EditedJun 27 2022, 9:53 AM

I pushed this change, but for some reason phabricator doesn't show it and close the review... I wonder if it's because I rebased it?

You forgot to add "Differential Revison: https://reviews.llvm.org/DXXXXXX" in the commit message, which is how Phabricator identifies the differential to close. I don't think it has anything to do with rebasing.

You forgot to add "Differential Revison: https://reviews.llvm.org/DXXXXXX" in the commit message, which is how Phabricator identifies the differential to close. I don't think it has anything to do with rebasing.

Oh, OK, that makes sense, oops.