Skip to content

Crash on invalid in Microsoft anonymous struct extension #12219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue Jan 24, 2012 · 6 comments
Closed

Crash on invalid in Microsoft anonymous struct extension #12219

llvmbot opened this issue Jan 24, 2012 · 6 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2012

Bugzilla Link 11847
Resolution FIXED
Resolved on Sep 17, 2014 19:42
Version trunk
OS Windows XP
Blocks llvm/llvm-bugzilla-archive#12477
Attachments Possible fix.
Reporter LLVM Bugzilla Contributor
CC @majnemer

Extended Description

The following invalid program crashes clang:

jason$ cat test.c
typedef struct { UNKNOWN c; } A;
typedef struct { A; } B;

jason$ clang -target i386-pc-win32 test.c
test.c:1:18: error: unknown type name 'UNKNOWN'
typedef struct { UNKNOWN c; } A;
^
test.c:2:18: warning: anonymous structs are a Microsoft extension [-Wmicrosoft]
typedef struct { A; } B;
^
Stack dump:
0. Program arguments: /Users/jason/Sources/llvm/build/release/bin/clang-3.1 -cc1 -triple i386-pc-win32 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -resource-dir /Users/jason/Sources/llvm/build/release/bin/../lib/clang/3.1 -fmodule-cache-path /var/folders/lf/36_5tdts1953gfg4mjwfmq8h0000gn/T/clang-module-cache -internal-isystem /Users/jason/Sources/llvm/build/release/bin/../lib/clang/3.1/include -internal-isystem C:/Program Files/Microsoft Visual Studio 10.0/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 9.0/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include -internal-isystem C:/Program Files/Microsoft Visual Studio 8/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include -fdebug-compilation-dir /Users/jason/Desktop/test -ferror-limit 19 -fmessage-length 173 -mstackrealign -fms-extensions -fms-compatibility -fmsc-version=1300 -fdelayed-template-parsing -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/lf/36_5tdts1953gfg4mjwfmq8h0000gn/T/test-Ct8Uam.o -x c test.c

  1. test.c:2:19: current parser token ';'
  2. test.c:2:9: parsing struct/union body
    clang-3: error: unable to execute command: Segmentation fault: 11
    clang-3: error: clang frontend command failed due to signal (use -v to see invocation)
    clang-3: note: diagnostic msg: Please submit a bug report to http://llvm.org/bugs/ and include command line arguments and all diagnostic information.
    clang-3: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
    clang-3: note: diagnostic msg: /var/folders/lf/36_5tdts1953gfg4mjwfmq8h0000gn/T/test-B8wNe4.i
    clang-3: note: diagnostic msg: /var/folders/lf/36_5tdts1953gfg4mjwfmq8h0000gn/T/test-B8wNe4.sh
@llvmbot
Copy link
Member Author

llvmbot commented Jan 24, 2012

assigned to @majnemer

@llvmbot
Copy link
Member Author

llvmbot commented Sep 17, 2014

Here is a related test case which crashes with -fms-extensions.

I am not sure what the treatment should be. Two possibilities:

  1. Issue error when used in sizeof.
  2. Just like c/c++'s undefined struct ignore it when used in sizeof.

struct anon_fault {
struct undefined;
};

int main()
{
return sizeof(struct anon_fault);
}

@llvmbot
Copy link
Member Author

llvmbot commented Sep 17, 2014

Forgot to add crash report:

clang -fms-extensions t.c

t.c:2:2: warning: anonymous structs are a Microsoft extension [-Wmicrosoft]
struct undefined;
^
Assertion failed: (D && "Cannot get layout of forward declarations!"), function getASTRecordLayout, file /Users/jahanian/sandbox/llvm-tot/tools/clang/lib/AST/RecordLayoutBuilder.cpp, line 2782.
0 clang 0x0000000110715a8e llvm::sys::PrintStackTrace(__sFILE*) + 46
1 clang 0x0000000110715d9b PrintStackTraceSignalHandler(void*) + 27
2 clang 0x00000001107161c5 SignalHandler(int) + 565
3 libsystem_platform.dylib 0x00007fff884dd5aa _sigtramp + 26
4 libsystem_platform.dylib 0x00007f8b73831f10 _sigtramp + 3946137984
5 clang 0x0000000110715dcb raise + 27
6 clang 0x0000000110715e82 abort + 18
7 clang 0x0000000110715e61 __assert_rtn + 129
8 clang 0x000000010ed87fcd clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const + 285
9 clang 0x000000010ea66f37 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const + 4951
10 clang 0x000000010ea65b05 clang::ASTContext::getTypeInfo(clang::Type const*) const + 165
11 clang 0x000000010ea6571e clang::ASTContext::getTypeInfoInChars(clang::Type const*) const + 126

@majnemer
Copy link
Mannequin

majnemer mannequin commented Sep 18, 2014

I've fixed this locally.

I went with the following approach:

  1. Call RequireCompleteType in BuildMicrosoftCAnonymousStruct using the type and location of the anonymous struct.
  2. If either RequireCompleteType or InjectAnonymousStructOrUnionMembers fail, set both the anonymous struct field and the parent context to invalid.

This mirrors what we do in more common cases.

We mark records invalid if they contain duplicate fields, this is essentially what InjectAnonymousStructOrUnionMembers is checking for.

We also mark records invalid if they contain fields which are incomplete, this is what RequireCompleteType is checking for.

@majnemer
Copy link
Mannequin

majnemer mannequin commented Sep 18, 2014

Fixed in r218006.

@timurrrr
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#12477

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

2 participants