[llvm-bugs] [Bug 51554] New: [clang][ParseEnum] Crashed: Enum with invalid use of incomplete type

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 19 23:16:49 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51554

            Bug ID: 51554
           Summary: [clang][ParseEnum] Crashed: Enum with invalid use of
                    incomplete type
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: guopeilin1 at huawei.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

I have a test case where clang should give an error message rather than a
crash.
The test command is `clang++ -O2 test.cpp`
The test case is as follows:
enum E { e = E() };

int main() {
  return 0;
}


The error message should be like the following:
test.cpp:1:14: error: invalid use of incomplete type 'E'
enum E { e = E() };
             ^~~
test.cpp:1:6: note: definition of 'E' is not complete until the closing '}'
enum E { e = E() };


However, the trunk get crashed with the assertion
The bug message:
```
./clang/include/clang/AST/Type.h:677: const clang::ExtQualsTypeCommonBase*
clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve
a NULL type pointer"' failed.
```

I did a simple analysis. 
In ParseDecl.cpp:
1. llvm-10: 
   AssignedVal.get(): NULL

2. llvm-12(Context.getLangOpts().RecoveryASTType: default
false)(early-version):
   AssignedVal.get(): RecoveryExpr 0xaaaaba19df20 '<dependent type>'
contains-errors lvalue

3. llvm-12(Context.getLangOpts().RecoveryASTType: default true)
(latest-version, Finally crashed):
   AssignedVal.get()->dump(): RecoveryExpr 0xaaaabb4d9500 'enum E'
contains-errors

In CheckEnumConstant(), EltTy(type: QualType, value: EnumType 0xaaaabb517dd0
'enum E') cannot use getIntWidth(), so crashed. But the code doesn't seem to be
wrong around here.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210820/633cf49c/attachment.html>


More information about the llvm-bugs mailing list