diff --git a/lib/llvm-ast.ts b/lib/llvm-ast.ts index fecef3b9e..58a9c4536 100644 --- a/lib/llvm-ast.ts +++ b/lib/llvm-ast.ts @@ -139,7 +139,28 @@ export class LlvmAstParser { // Refers to whatever the most recent file specified was const lineRegex = /<(col|line):/; - let mostRecentIsSource = false; + // Intra-line filters + const addressRegex = /^([^A-Za-z]*[A-Za-z]+) 0x[\da-z]+/gm; + const slocRegex2 = / ?>?/g; + + let mostRecentIsSource: boolean = false; + + const isBlockUserSource = (output: ResultLine[], start: number, mostRecentIsSource: boolean) => { + for (let i = start + 1; i < output.length; ++i) { + if (topLevelRegex.test(output[i].text)) { + // Scanned through the block without encountering new info + return mostRecentIsSource; + } + if (systemSource.test(output[i].text)) { + return false; + } + if (userSource.test(output[i].text)) { + return true; + } + } + // Reached the end with no new info + return mostRecentIsSource; + }; // Remove all AST nodes which aren't directly from the user's source code for (let i = 0; i < output.length; ++i) { @@ -156,9 +177,10 @@ export class LlvmAstParser { // skip ast from this source } else if (userSource.test(output[i].text)) { continue; - } else if (!slocRegex.test(output[i].text)) { - mostRecentIsSource = false; - continue; + } else { + // if (!slocRegex.test(output[i].text)) { + mostRecentIsSource = isBlockUserSource(output, i, mostRecentIsSource); + if (mostRecentIsSource) continue; } let spliceMax = i + 1; @@ -170,11 +192,9 @@ export class LlvmAstParser { } } // Filter out the symbol addresses - const addressRegex = /^([^A-Za-z]*[A-Za-z]+) 0x[\da-z]+/gm; output[i].text = output[i].text.replace(addressRegex, '$1'); // Filter out and <> - const slocRegex2 = / ?>?/g; output[i].text = output[i].text.replace(slocRegex2, ''); // Unify file references diff --git a/test/ast/bug-5889.ast b/test/ast/bug-5889.ast new file mode 100644 index 000000000..2303c5b66 --- /dev/null +++ b/test/ast/bug-5889.ast @@ -0,0 +1,307 @@ +TranslationUnitDecl +|-NamespaceDecl 0x556ca9466ac0 prev 0x556ca9466440 line:329:11 std +| |-original Namespace 0x556ca9466440 'std' +| `-NamespaceDecl col:20 __cxx11 inline +| `-AbiTagAttr cxx11 +|-NamespaceDecl 0x556ca9466cb8 line:333:11 __gnu_cxx +| `-NamespaceDecl col:20 __cxx11 inline +| `-AbiTagAttr cxx11 +|-NamespaceDecl 0x556ca9466e38 prev 0x556ca9466ac0 line:508:11 std +| |-original Namespace 0x556ca9466440 'std' +| `-FunctionDecl line:516:3 used constexpr __is_constant_evaluated 'bool () noexcept' inline +| |-CompoundStmt +| | `-ReturnStmt +| | `-CallExpr 'bool' +| | `-ImplicitCastExpr 'bool (*)() noexcept' +| | `-DeclRefExpr '' Function 0x556ca9467050 '__builtin_is_constant_evaluated' 'bool () noexcept' +| `-VisibilityAttr Implicit Default +|-LinkageSpecDecl 0x556ca9467000 col:12 implicit C +| `-FunctionDecl col:12 implicit used __builtin_is_constant_evaluated 'bool () noexcept' extern +| |-BuiltinAttr Implicit 460 +| `-NoThrowAttr Implicit +|-TypedefDecl 0x556ca94bf770 col:16 referenced _Float64 'double' +| `-BuiltinType 'double' +|-TypedefDecl 0x556ca94bf7e0 col:16 referenced _Float32x 'double' +| `-BuiltinType 'double' +|-TypedefDecl 0x556ca94bf850 col:21 referenced _Float64x 'long double' +| `-BuiltinType 'long double' +|-TypedefDecl 0x556ca94bff68 col:3 referenced __mbstate_t 'struct __mbstate_t':'__mbstate_t' +| `-ElaboratedType 'struct __mbstate_t' sugar +| `-RecordType '__mbstate_t' +| `-CXXRecord '' +|-TypedefDecl 0x556ca94c01b0 col:25 referenced __FILE 'struct _IO_FILE':'_IO_FILE' +| `-ElaboratedType 'struct _IO_FILE' sugar +| `-RecordType '_IO_FILE' +| `-CXXRecord '_IO_FILE' +|-TypedefDecl 0x556ca94c02b8 col:25 referenced FILE 'struct _IO_FILE':'_IO_FILE' +| `-ElaboratedType 'struct _IO_FILE' sugar +| `-RecordType '_IO_FILE' +| `-CXXRecord '_IO_FILE' +|-TypedefDecl 0x556ca94ddf30 col:33 referenced __locale_t 'struct __locale_struct *' +| `-PointerType 'struct __locale_struct *' +| `-ElaboratedType 'struct __locale_struct' sugar +| `-RecordType '__locale_struct' +| `-CXXRecord '__locale_struct' +|-LinkageSpecDecl 0x556ca94fb548 line:135:8 C++ +| `-NamespaceDecl prev 0x556ca94fb3c8 line:137:11 std +| |-original Namespace 0x556ca9466440 'std' +| |-VisibilityAttr Default +| |-UsingDecl col:11 ::wint_t +| |-UsingShadowDecl col:11 implicit Typedef 0x556ca94bfa00 'wint_t' +| | `-TypedefType 'wint_t' sugar +| | |-Typedef 'wint_t' +| | `-BuiltinType 'unsigned int' +| |-UsingDecl col:11 ::btowc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e87b8 'btowc' 'wint_t (int) noexcept(true)' +| |-UsingDecl col:11 ::fgetwc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f7b58 'fgetwc' 'wint_t (__FILE *)' +| |-UsingDecl col:11 ::fgetws +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f8760 'fgetws' 'wchar_t *(wchar_t *__restrict, int, __FILE *__restrict)' +| |-UsingDecl col:11 ::fputwc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f80a8 'fputwc' 'wint_t (wchar_t, __FILE *)' +| |-UsingDecl col:11 ::fputws +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f89d0 'fputws' 'int (const wchar_t *__restrict, __FILE *__restrict)' +| |-UsingDecl col:11 ::fwide +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f30a0 'fwide' 'int (__FILE *, int) noexcept(true)' +| |-UsingDecl col:11 ::fwprintf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f3318 'fwprintf' 'int (__FILE *__restrict, const wchar_t *__restrict, ...)' +| |-UsingDecl col:11 ::fwscanf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f5b60 'fwscanf' 'int (__FILE *__restrict, const wchar_t *__restrict, ...)' +| |-UsingDecl col:11 ::getwc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f7cb0 'getwc' 'wint_t (__FILE *)' +| |-UsingDecl col:11 ::getwchar +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f7e58 'getwchar' 'wint_t ()' +| |-UsingDecl col:11 ::mbrlen +| |-UsingShadowDecl col:11 implicit Function 0x556ca94eaa58 'mbrlen' 'size_t (const char *__restrict, size_t, mbstate_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::mbrtowc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e90e8 'mbrtowc' 'size_t (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::mbsinit +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e8c70 'mbsinit' 'int (const mbstate_t *) noexcept(true)' +| |-UsingDecl col:11 ::mbsrtowcs +| |-UsingShadowDecl col:11 implicit Function 0x556ca94eae58 'mbsrtowcs' 'size_t (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::putwc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f8288 'putwc' 'wint_t (wchar_t, __FILE *)' +| |-UsingDecl col:11 ::putwchar +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f8468 'putwchar' 'wint_t (wchar_t)' +| |-UsingDecl col:11 ::swprintf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f3838 'swprintf' 'int (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...) noexcept(true)' +| |-UsingDecl col:11 ::swscanf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f6118 'swscanf' 'int (const wchar_t *__restrict, const wchar_t *__restrict, ...) noexcept(true)' +| |-UsingDecl col:11 ::ungetwc +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f8c28 'ungetwc' 'wint_t (wint_t, __FILE *)' +| |-UsingDecl col:11 ::vfwprintf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f3c00 'vfwprintf' 'int (__FILE *__restrict, const wchar_t *__restrict, __va_list_tag *)' +| |-UsingDecl col:11 ::vfwscanf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f6c48 'vfwscanf' 'int (__FILE *__restrict, const wchar_t *__restrict, __va_list_tag *)' +| |-UsingDecl col:11 ::vswprintf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f52b0 'vswprintf' 'int (wchar_t *__restrict, size_t, const wchar_t *__restrict, __va_list_tag *) noexcept(true)' +| |-UsingDecl col:11 ::vswscanf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f7910 'vswscanf' 'int (const wchar_t *__restrict, const wchar_t *__restrict, __va_list_tag *) noexcept(true)' +| |-UsingDecl col:11 ::vwprintf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f4ee0 'vwprintf' 'int (const wchar_t *__restrict, __va_list_tag *)' +| |-UsingDecl col:11 ::vwscanf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f7578 'vwscanf' 'int (const wchar_t *__restrict, __va_list_tag *)' +| |-UsingDecl col:11 ::wcrtomb +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e9428 'wcrtomb' 'size_t (char *__restrict, wchar_t, mbstate_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcscat +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e0de0 'wcscat' 'wchar_t *(wchar_t *__restrict, const wchar_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcscmp +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e14e0 'wcscmp' 'int (const wchar_t *, const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wcscoll +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e2a10 'wcscoll' 'int (const wchar_t *, const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wcscpy +| |-UsingShadowDecl col:11 implicit Function 0x556ca94de490 'wcscpy' 'wchar_t *(wchar_t *__restrict, const wchar_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcscspn +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e5278 'wcscspn' 'size_t (const wchar_t *, const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wcsftime +| |-UsingShadowDecl col:11 implicit Function 0x556ca94fae88 'wcsftime' 'size_t (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcslen +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e60f8 'wcslen' 'size_t (const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wcsncat +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e1180 'wcsncat' 'wchar_t *(wchar_t *__restrict, const wchar_t *__restrict, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wcsncmp +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e1950 'wcsncmp' 'int (const wchar_t *, const wchar_t *, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wcsncpy +| |-UsingShadowDecl col:11 implicit Function 0x556ca94de8e0 'wcsncpy' 'wchar_t *(wchar_t *__restrict, const wchar_t *__restrict, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wcsrtombs +| |-UsingShadowDecl col:11 implicit Function 0x556ca94eb258 'wcsrtombs' 'size_t (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcsspn +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e5538 'wcsspn' 'size_t (const wchar_t *, const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wcstod +| |-UsingShadowDecl col:11 implicit Function 0x556ca94ec2a0 'wcstod' 'double (const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcstof +| |-UsingShadowDecl col:11 implicit Function 0x556ca94ec570 'wcstof' 'float (const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcstok +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e5ef0 'wcstok' 'wchar_t *(wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcstol +| |-UsingShadowDecl col:11 implicit Function 0x556ca94edec0 'wcstol' 'long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +| |-UsingDecl col:11 ::wcstoul +| |-UsingShadowDecl col:11 implicit Function 0x556ca94ee200 'wcstoul' 'unsigned long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +| |-UsingDecl col:11 ::wcsxfrm +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e2d68 'wcsxfrm' 'size_t (wchar_t *__restrict, const wchar_t *__restrict, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wctob +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e89b0 'wctob' 'int (wint_t) noexcept(true)' +| |-UsingDecl col:11 ::wmemcmp +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e7710 'wmemcmp' 'int (const wchar_t *, const wchar_t *, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wmemcpy +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e7a90 'wmemcpy' 'wchar_t *(wchar_t *__restrict, const wchar_t *__restrict, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wmemmove +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e7e60 'wmemmove' 'wchar_t *(wchar_t *, const wchar_t *, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wmemset +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e8230 'wmemset' 'wchar_t *(wchar_t *, wchar_t, size_t) noexcept(true)' +| |-UsingDecl col:11 ::wprintf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f34f8 'wprintf' 'int (const wchar_t *__restrict, ...)' +| |-UsingDecl col:11 ::wscanf +| |-UsingShadowDecl col:11 implicit Function 0x556ca94f5e00 'wscanf' 'int (const wchar_t *__restrict, ...)' +| |-UsingDecl col:11 ::wcschr +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e3930 'wcschr' 'wchar_t *(const wchar_t *, wchar_t) noexcept(true)' +| |-UsingDecl col:11 ::wcspbrk +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e5840 'wcspbrk' 'wchar_t *(const wchar_t *, const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wcsrchr +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e4cc0 'wcsrchr' 'wchar_t *(const wchar_t *, wchar_t) noexcept(true)' +| |-UsingDecl col:11 ::wcsstr +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e5b00 'wcsstr' 'wchar_t *(const wchar_t *, const wchar_t *) noexcept(true)' +| |-UsingDecl col:11 ::wmemchr +| |-UsingShadowDecl col:11 implicit Function 0x556ca94e6ac0 'wmemchr' 'wchar_t *(const wchar_t *, wchar_t, size_t) noexcept(true)' +| |-FunctionDecl line:214:3 wcschr 'wchar_t *(wchar_t *, wchar_t)' inline +| | |-ParmVarDecl col:19 used __p 'wchar_t *' +| | |-ParmVarDecl col:32 used __c 'wchar_t' +| | `-CompoundStmt +| | `-ReturnStmt +| | `-CallExpr 'wchar_t *' +| | |-ImplicitCastExpr 'wchar_t *(*)(const wchar_t *, wchar_t) noexcept(true)' +| | | `-DeclRefExpr 'wchar_t *(const wchar_t *, wchar_t) noexcept(true)' lvalue Function 0x556ca94e3930 'wcschr' 'wchar_t *(const wchar_t *, wchar_t) noexcept(true)' (UsingShadow 0x556ca94fe660 'wcschr') +| | |-CXXConstCastExpr 'const wchar_t *' const_cast +| | | `-ImplicitCastExpr 'wchar_t *' part_of_explicit_cast +| | | `-DeclRefExpr 'wchar_t *' lvalue ParmVar 0x556ca94fe9d8 '__p' 'wchar_t *' +| | `-ImplicitCastExpr 'wchar_t' +| | `-DeclRefExpr 'wchar_t' lvalue ParmVar 0x556ca94fea50 '__c' 'wchar_t' +| |-FunctionDecl line:218:3 wcspbrk 'wchar_t *(wchar_t *, const wchar_t *)' inline +| | |-ParmVarDecl col:20 used __s1 'wchar_t *' +| | |-ParmVarDecl col:41 used __s2 'const wchar_t *' +| | `-CompoundStmt +| | `-ReturnStmt +| | `-CallExpr 'wchar_t *' +| | |-ImplicitCastExpr 'wchar_t *(*)(const wchar_t *, const wchar_t *) noexcept(true)' +| | | `-DeclRefExpr 'wchar_t *(const wchar_t *, const wchar_t *) noexcept(true)' lvalue Function 0x556ca94e5840 'wcspbrk' 'wchar_t *(const wchar_t *, const wchar_t *) noexcept(true)' (UsingShadow 0x556ca94fe720 'wcspbrk') +| | |-CXXConstCastExpr 'const wchar_t *' const_cast +| | | `-ImplicitCastExpr 'wchar_t *' part_of_explicit_cast +| | | `-DeclRefExpr 'wchar_t *' lvalue ParmVar 0x556ca94ff638 '__s1' 'wchar_t *' +| | `-ImplicitCastExpr 'const wchar_t *' +| | `-DeclRefExpr 'const wchar_t *' lvalue ParmVar 0x556ca94ff6b8 '__s2' 'const wchar_t *' +| |-FunctionDecl line:222:3 wcsrchr 'wchar_t *(wchar_t *, wchar_t)' inline +| | |-ParmVarDecl col:20 used __p 'wchar_t *' +| | |-ParmVarDecl col:33 used __c 'wchar_t' +| | `-CompoundStmt +| | `-ReturnStmt +| | `-CallExpr 'wchar_t *' +| | |-ImplicitCastExpr 'wchar_t *(*)(const wchar_t *, wchar_t) noexcept(true)' +| | | `-DeclRefExpr 'wchar_t *(const wchar_t *, wchar_t) noexcept(true)' lvalue Function 0x556ca94e4cc0 'wcsrchr' 'wchar_t *(const wchar_t *, wchar_t) noexcept(true)' (UsingShadow 0x556ca94fe7e0 'wcsrchr') +| | |-CXXConstCastExpr 'const wchar_t *' const_cast +| | | `-ImplicitCastExpr 'wchar_t *' part_of_explicit_cast +| | | `-DeclRefExpr 'wchar_t *' lvalue ParmVar 0x556ca94ffa68 '__p' 'wchar_t *' +| | `-ImplicitCastExpr 'wchar_t' +| | `-DeclRefExpr 'wchar_t' lvalue ParmVar 0x556ca94ffae0 '__c' 'wchar_t' +| |-FunctionDecl line:226:3 wcsstr 'wchar_t *(wchar_t *, const wchar_t *)' inline +| | |-ParmVarDecl col:19 used __s1 'wchar_t *' +| | |-ParmVarDecl col:40 used __s2 'const wchar_t *' +| | `-CompoundStmt +| | `-ReturnStmt +| | `-CallExpr 'wchar_t *' +| | |-ImplicitCastExpr 'wchar_t *(*)(const wchar_t *, const wchar_t *) noexcept(true)' +| | | `-DeclRefExpr 'wchar_t *(const wchar_t *, const wchar_t *) noexcept(true)' lvalue Function 0x556ca94e5b00 'wcsstr' 'wchar_t *(const wchar_t *, const wchar_t *) noexcept(true)' (UsingShadow 0x556ca94fe8a0 'wcsstr') +| | |-CXXConstCastExpr 'const wchar_t *' const_cast +| | | `-ImplicitCastExpr 'wchar_t *' part_of_explicit_cast +| | | `-DeclRefExpr 'wchar_t *' lvalue ParmVar 0x556ca94ffe28 '__s1' 'wchar_t *' +| | `-ImplicitCastExpr 'const wchar_t *' +| | `-DeclRefExpr 'const wchar_t *' lvalue ParmVar 0x556ca94ffea8 '__s2' 'const wchar_t *' +| `-FunctionDecl line:230:3 wmemchr 'wchar_t *(wchar_t *, wchar_t, size_t)' inline +| |-ParmVarDecl col:20 used __p 'wchar_t *' +| |-ParmVarDecl col:33 used __c 'wchar_t' +| |-ParmVarDecl col:45 used __n 'size_t':'unsigned long' +| `-CompoundStmt +| `-ReturnStmt +| `-CallExpr 'wchar_t *' +| |-ImplicitCastExpr 'wchar_t *(*)(const wchar_t *, wchar_t, size_t) noexcept(true)' +| | `-DeclRefExpr 'wchar_t *(const wchar_t *, wchar_t, size_t) noexcept(true)' lvalue Function 0x556ca94e6ac0 'wmemchr' 'wchar_t *(const wchar_t *, wchar_t, size_t) noexcept(true)' (UsingShadow 0x556ca94fe960 'wmemchr') +| |-CXXConstCastExpr 'const wchar_t *' const_cast +| | `-ImplicitCastExpr 'wchar_t *' part_of_explicit_cast +| | `-DeclRefExpr 'wchar_t *' lvalue ParmVar 0x556ca95001f8 '__p' 'wchar_t *' +| |-ImplicitCastExpr 'wchar_t' +| | `-DeclRefExpr 'wchar_t' lvalue ParmVar 0x556ca9500270 '__c' 'wchar_t' +| `-ImplicitCastExpr 'size_t':'unsigned long' +| `-DeclRefExpr 'size_t':'unsigned long' lvalue ParmVar 0x556ca9500350 '__n' 'size_t':'unsigned long' +|-NamespaceDecl 0x556ca95007e0 prev 0x556ca9466cb8 line:244:11 __gnu_cxx +| |-original Namespace 0x556ca9466cb8 '__gnu_cxx' +| |-UsingDecl col:11 ::wcstold +| |-UsingShadowDecl col:11 implicit Function 0x556ca94ec820 'wcstold' 'long double (const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:11 ::wcstoll +| |-UsingShadowDecl col:11 implicit Function 0x556ca94ee540 'wcstoll' 'long long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +| |-UsingDecl col:11 ::wcstoull +| `-UsingShadowDecl col:11 implicit Function 0x556ca94ee880 'wcstoull' 'unsigned long long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +|-NamespaceDecl 0x556ca9500a90 prev 0x556ca94fb5b8 line:265:11 std +| |-original Namespace 0x556ca9466440 'std' +| |-UsingDecl col:22 ::__gnu_cxx::wcstold +| |-UsingShadowDecl col:22 implicit Function 0x556ca94ec820 'wcstold' 'long double (const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:22 ::__gnu_cxx::wcstoll +| |-UsingShadowDecl col:22 implicit Function 0x556ca94ee540 'wcstoll' 'long long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +| |-UsingDecl col:22 ::__gnu_cxx::wcstoull +| `-UsingShadowDecl col:22 implicit Function 0x556ca94ee880 'wcstoull' 'unsigned long long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +|-NamespaceDecl 0x556ca9500d70 prev 0x556ca9500a90 line:280:11 std +| |-original Namespace 0x556ca9466440 'std' +| |-UsingDecl col:14 std::wcstof +| |-UsingShadowDecl prev 0x556ca94fdd60 col:14 implicit Function 0x556ca94ec570 'wcstof' 'float (const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:14 std::vfwscanf +| |-UsingShadowDecl prev 0x556ca94fc6c0 col:14 implicit Function 0x556ca94f6c48 'vfwscanf' 'int (__FILE *__restrict, const wchar_t *__restrict, __va_list_tag *)' +| |-UsingDecl col:14 std::vswscanf +| |-UsingShadowDecl prev 0x556ca94fc840 col:14 implicit Function 0x556ca94f7910 'vswscanf' 'int (const wchar_t *__restrict, const wchar_t *__restrict, __va_list_tag *) noexcept(true)' +| |-UsingDecl col:14 std::vwscanf +| |-UsingShadowDecl prev 0x556ca94fc9c0 col:14 implicit Function 0x556ca94f7578 'vwscanf' 'int (const wchar_t *__restrict, __va_list_tag *)' +| |-UsingDecl col:14 std::wcstold +| |-UsingShadowDecl prev 0x556ca9500b80 col:14 implicit Function 0x556ca94ec820 'wcstold' 'long double (const wchar_t *__restrict, wchar_t **__restrict) noexcept(true)' +| |-UsingDecl col:14 std::wcstoll +| |-UsingShadowDecl prev 0x556ca9500c48 col:14 implicit Function 0x556ca94ee540 'wcstoll' 'long long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +| |-UsingDecl col:14 std::wcstoull +| `-UsingShadowDecl prev 0x556ca9500d10 col:14 implicit Function 0x556ca94ee880 'wcstoull' 'unsigned long long (const wchar_t *__restrict, wchar_t **__restrict, int) noexcept(true)' +|-LinkageSpecDecl 0x556ca96787b0 col:7 implicit C +| `-FunctionDecl col:7 implicit used __builtin_memmove 'void *(void *, const void *, unsigned long) noexcept' extern +| |-ParmVarDecl 'void *' +| |-ParmVarDecl 'const void *' +| |-ParmVarDecl 'unsigned long' +| |-BuiltinAttr Implicit 413 +| `-NoThrowAttr Implicit +|-LinkageSpecDecl 0x556ca967a348 col:7 implicit C +| `-FunctionDecl col:7 implicit used __builtin_memcpy 'void *(void *, const void *, unsigned long) noexcept' extern +| |-ParmVarDecl 'void *' +| |-ParmVarDecl 'const void *' +| |-ParmVarDecl 'unsigned long' +| |-BuiltinAttr Implicit 411 +| `-NoThrowAttr Implicit +|-LinkageSpecDecl 0x556ca967b110 col:27 implicit C +| `-FunctionDecl col:27 implicit referenced __builtin_addressof 'void *(void &) noexcept' extern +| |-ParmVarDecl 'void &' +| | `-LifetimeBoundAttr Implicit +| |-BuiltinAttr Implicit 1225 +| |-NoThrowAttr Implicit +| `-ConstAttr Implicit +|-LinkageSpecDecl 0x556ca967b480 col:4 implicit C +| `-FunctionDecl col:4 implicit used __builtin_memset 'void *(void *, int, unsigned long) noexcept' extern +| |-ParmVarDecl 'void *' +| |-ParmVarDecl 'int' +| |-ParmVarDecl 'unsigned long' +| |-BuiltinAttr Implicit 415 +| `-NoThrowAttr Implicit +`-FunctionDecl 0x3f1d2b48 line:2:13 square 'std::string (int &)' + |-ParmVarDecl 0x3f1d2a40 col:25 used num 'int &' + `-CompoundStmt 0x3f1d2e80 + |-CompoundAssignOperator 0x3f1d2c50 'int' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int' + | |-DeclRefExpr 0x3f1d2bf8 'int' lvalue ParmVar 0x3f1d2a40 'num' 'int &' + | `-ImplicitCastExpr 0x3f1d2c38 'int' + | `-DeclRefExpr 0x3f1d2c18 'int' lvalue ParmVar 0x3f1d2a40 'num' 'int &' + `-ReturnStmt 0x3f1d2e70 + `-ExprWithCleanups 0x3f1d2e58 'std::string':'std::basic_string' + `-ImplicitCastExpr 0x3f1d2e40 'std::string':'std::basic_string' + `-CXXConstructExpr 0x3f1d2e08 'std::string':'std::basic_string' 'void (const char *, const std::allocator &)' + |-ImplicitCastExpr 0x3f1d2cf0 'const char *' + | `-StringLiteral 0x3f1d2c80 'const char[8]' lvalue "success" + `-CXXDefaultArgExpr 0x3f1d2db8 <> 'const std::allocator':'const std::allocator' lvalue diff --git a/test/ast/bug-5889.cpp b/test/ast/bug-5889.cpp new file mode 100644 index 000000000..5ce34d7c2 --- /dev/null +++ b/test/ast/bug-5889.cpp @@ -0,0 +1,5 @@ +#include +std::string square(int& num) { + num *= num; + return "success"; +} diff --git a/test/llvm-ast-parser-tests.ts b/test/llvm-ast-parser-tests.ts index cc9917f3a..63873e384 100644 --- a/test/llvm-ast-parser-tests.ts +++ b/test/llvm-ast-parser-tests.ts @@ -149,3 +149,24 @@ describe('llvm-ast bug-3849b', function () { processed.length.should.be.below(300); }); }); + +describe('llvm-ast bug-5889', function () { + let compilerProps; + let astParser; + let astDump; + let compilerOutput; + + before(() => { + const fakeProps = new properties.CompilerProps(languages, properties.fakeProps({})); + compilerProps = (fakeProps.get as any).bind(fakeProps, 'c++'); + + astParser = new LlvmAstParser(compilerProps); + astDump = utils.splitLines(fs.readFileSync('test/ast/bug-5889.ast').toString()); + compilerOutput = mockAstOutput(astDump); + }); + + it('should have not too many lines', () => { + const processed = astParser.processAst(compilerOutput); + processed.length.should.be.below(50); + }); +});