This is an archive of the discontinued LLVM Phabricator instance.

[pseudo] Fix an out-of-bound error in LRTable::find.
ClosedPublic

Authored by hokein on Mar 1 2022, 6:53 AM.

Details

Summary

The linear scan should not escape the TargetedStates range.

Diff Detail

Event Timeline

hokein requested review of this revision.Mar 1 2022, 6:53 AM
hokein created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 6:53 AM
sammccall accepted this revision.Mar 1 2022, 6:55 AM
sammccall added inline comments.
clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
114–115

I think this check is no longer needed

This revision is now accepted and ready to land.Mar 1 2022, 6:55 AM
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 12:54 AM

I'm seeing debug failures again on Windows after this.

FAIL: Clang :: Syntax/lr-build-conflicts.test (14728 of 14729)
******************** TEST 'Clang :: Syntax/lr-build-conflicts.test' FAILED ********************
Script:
--
: 'RUN: at line 5';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-graph | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test --check-prefix=GRAPH
: 'RUN: at line 30';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-table | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test --check-prefix=TABLE
--
Exit Code: 2

Command Output (stdout):
--
$ ":" "RUN: at line 5"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "-print-graph"
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "--check-prefix=GRAPH"
$ ":" "RUN: at line 30"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "-print-table"
note: command had no output on stdout or stderr
error: command failed with exit status: 3221226505
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "--check-prefix=TABLE"
# command stderr:
FileCheck error: '<stdin>' is empty.
FileCheck command line:  f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test --check-prefix=TABLE

error: command failed with exit status: 2

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: Clang :: Syntax/lr-build-basic.test (14729 of 14729)
******************** TEST 'Clang :: Syntax/lr-build-basic.test' FAILED ********************
Script:
--
: 'RUN: at line 5';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-graph | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test --check-prefix=GRAPH
: 'RUN: at line 18';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-table | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test --check-prefix=TABLE
--
Exit Code: 2

Command Output (stdout):
--
$ ":" "RUN: at line 5"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-graph"
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "--check-prefix=GRAPH"
$ ":" "RUN: at line 18"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-table"
note: command had no output on stdout or stderr
error: command failed with exit status: 3221226505
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "--check-prefix=TABLE"
# command stderr:
FileCheck error: '<stdin>' is empty.
FileCheck command line:  f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test --check-prefix=TABLE

error: command failed with exit status: 2

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
********************
Failed Tests (2):
  Clang :: Syntax/lr-build-basic.test
  Clang :: Syntax/lr-build-conflicts.test


Testing Time: 336.94s
  Unsupported      :  1727
  Passed           : 12972
  Expectedly Failed:    28
  Failed           :     2

It looks to be another index out of bounds assert with the MSVC STL debug iterators. Can you fix or revert?

hokein added a comment.Mar 3 2022, 5:10 AM

I'm seeing debug failures again on Windows after this.

FAIL: Clang :: Syntax/lr-build-conflicts.test (14728 of 14729)
******************** TEST 'Clang :: Syntax/lr-build-conflicts.test' FAILED ********************
Script:
--
: 'RUN: at line 5';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-graph | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test --check-prefix=GRAPH
: 'RUN: at line 30';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-table | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test --check-prefix=TABLE
--
Exit Code: 2

Command Output (stdout):
--
$ ":" "RUN: at line 5"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "-print-graph"
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "--check-prefix=GRAPH"
$ ":" "RUN: at line 30"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "-print-table"
note: command had no output on stdout or stderr
error: command failed with exit status: 3221226505
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" "--check-prefix=TABLE"
# command stderr:
FileCheck error: '<stdin>' is empty.
FileCheck command line:  f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test --check-prefix=TABLE

error: command failed with exit status: 2

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: Clang :: Syntax/lr-build-basic.test (14729 of 14729)
******************** TEST 'Clang :: Syntax/lr-build-basic.test' FAILED ********************
Script:
--
: 'RUN: at line 5';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-graph | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test --check-prefix=GRAPH
: 'RUN: at line 18';   clang-pseudo -grammar F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-table | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test --check-prefix=TABLE
--
Exit Code: 2

Command Output (stdout):
--
$ ":" "RUN: at line 5"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-graph"
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "--check-prefix=GRAPH"
$ ":" "RUN: at line 18"
$ "clang-pseudo" "-grammar" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-table"
note: command had no output on stdout or stderr
error: command failed with exit status: 3221226505
$ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "--check-prefix=TABLE"
# command stderr:
FileCheck error: '<stdin>' is empty.
FileCheck command line:  f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test --check-prefix=TABLE

error: command failed with exit status: 2

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
********************
Failed Tests (2):
  Clang :: Syntax/lr-build-basic.test
  Clang :: Syntax/lr-build-conflicts.test


Testing Time: 336.94s
  Unsupported      :  1727
  Passed           : 12972
  Expectedly Failed:    28
  Failed           :     2

It looks to be another index out of bounds assert with the MSVC STL debug iterators. Can you fix or revert?

oops.. sorry. Looking at it now.

hokein added a comment.Mar 3 2022, 5:30 AM
clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
114–115

sorry, should have thought more carefully on this comment, we need this check to make sure we don't access Actions[Actions.end()] on Line120 below.

Thanks! I can confirm this is fixed on my end now.

sammccall added inline comments.Mar 3 2022, 7:30 AM
clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
114–115

Sorry about that.

You're right, we formally do &*Actions[Actions.size()], which is invalid.

However we don't actually need a runtime check, just a change of syntax to avoid the dereference:

return llvm::makeArrayRef(Actions.data() + (Start - States.data()), End - Start);