[llvm] r175063 - [ms-inline-asm] Use an array_pod_sort, rather than a std:sort.

Timur Iskhodzhanov timurrrr at google.com
Fri Feb 15 09:39:43 PST 2013


Attached is the stacktrace just in case

2013/2/15 Timur Iskhodzhanov <timurrrr at google.com>:
> OK, here we go.
>
> The crash happens if you "#include <windows.h>" on a machine with
> VS2010 installed (other versions might be affected too).
>
> Here's a patch that adds an assert that crashes:
> ---------------------------------------------------------------------------------
> diff --git lib/MC/MCParser/AsmParser.cpp lib/MC/MCParser/AsmParser.cpp
> index 2cce8b0..1cfd5f6 100644
> --- lib/MC/MCParser/AsmParser.cpp
> +++ lib/MC/MCParser/AsmParser.cpp
> @@ -4174,8 +4174,10 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc,
> std::string &AsmString,
>
>      // Emit everything up to the immediate/expression.  If the previous rewrite
>      // was a size directive, then this has already been done.
> -    if (PrevKind != AOK_SizeDirective)
> +    if (PrevKind != AOK_SizeDirective) {
> +      assert(Loc >= Start);
>        OS << StringRef(Start, Loc - Start);
> +    }
>      PrevKind = Kind;
>
>      // Skip the original expression.
> ---------------------------------------------------------------------------------
>
>
> I hope that's enough info to debug :)
>
>
> FYI The bug was hard to debug as a substantial part of memory was
> corrupted (including EBPs, return addresses etc)
> so I propose something like this to prevent such bugs from re-appearing:
> ---------------------------------------------------------------------------------
> diff --git include/llvm/ADT/StringRef.h include/llvm/ADT/StringRef.h
> index 1e21d92..077c056 100644
> --- include/llvm/ADT/StringRef.h
> +++ include/llvm/ADT/StringRef.h
> @@ -84,6 +84,7 @@ namespace llvm {
>        : Data(data), Length(length) {
>          assert((data || length == 0) &&
>          "StringRef cannot be built from a NULL argument with non-null length");
> +        assert(length < 0x80000000 && "length looks suspicious");
>        }
>
>      /// Construct a string ref from an std::string.
> ---------------------------------------------------------------------------------
>
> 2013/2/15 Timur Iskhodzhanov <timurrrr at google.com>:
>> FYI this crashes on my Windows bot.
>>
>> I'll update with the details when I reproduce locally.
>>
>> 2013/2/13 Chad Rosier <mcrosier at apple.com>:
>>> Author: mcrosier
>>> Date: Wed Feb 13 12:38:58 2013
>>> New Revision: 175063
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=175063&view=rev
>>> Log:
>>> [ms-inline-asm] Use an array_pod_sort, rather than a std:sort.
>>>
>>>
>>> Modified:
>>>     llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>>
>>> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=175063&r1=175062&r2=175063&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
>>> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Feb 13 12:38:58 2013
>>> @@ -13,6 +13,7 @@
>>>
>>>  #include "llvm/ADT/APFloat.h"
>>>  #include "llvm/ADT/SmallString.h"
>>> +#include "llvm/ADT/STLExtras.h"
>>>  #include "llvm/ADT/StringMap.h"
>>>  #include "llvm/ADT/Twine.h"
>>>  #include "llvm/MC/MCAsmInfo.h"
>>> @@ -4029,8 +4030,14 @@ bool AsmParser::ParseDirectiveMSAlign(SM
>>>    return false;
>>>  }
>>>
>>> -bool AsmStringSort (AsmRewrite A, AsmRewrite B) {
>>> -  return A.Loc.getPointer() < B.Loc.getPointer();
>>> +static int RewritesSort (const void *A, const void *B) {
>>> +  const AsmRewrite *AsmRewriteA = static_cast<const AsmRewrite*>(A);
>>> +  const AsmRewrite *AsmRewriteB = static_cast<const AsmRewrite*>(B);
>>> +  if (AsmRewriteA->Loc.getPointer() < AsmRewriteB->Loc.getPointer())
>>> +    return -1;
>>> +  if (AsmRewriteB->Loc.getPointer() < AsmRewriteA->Loc.getPointer())
>>> +    return 1;
>>> +  return 0;
>>>  }
>>>
>>>  bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
>>> @@ -4157,7 +4164,7 @@ bool AsmParser::ParseMSInlineAsm(void *A
>>>    AsmRewriteKind PrevKind = AOK_Imm;
>>>    raw_string_ostream OS(AsmStringIR);
>>>    const char *Start = SrcMgr.getMemoryBuffer(0)->getBufferStart();
>>> -  std::sort (AsmStrRewrites.begin(), AsmStrRewrites.end(), AsmStringSort);
>>> +  array_pod_sort (AsmStrRewrites.begin(), AsmStrRewrites.end(), RewritesSort);
>>>    for (SmallVectorImpl<struct AsmRewrite>::iterator
>>>           I = AsmStrRewrites.begin(), E = AsmStrRewrites.end(); I != E; ++I) {
>>>      const char *Loc = (*I).Loc.getPointer();
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

2013/2/15 Timur Iskhodzhanov <timurrrr at google.com>:
> OK, here we go.
>
> The crash happens if you "#include <windows.h>" on a machine with
> VS2010 installed (other versions might be affected too).
>
> Here's a patch that adds an assert that crashes:
> ---------------------------------------------------------------------------------
> diff --git lib/MC/MCParser/AsmParser.cpp lib/MC/MCParser/AsmParser.cpp
> index 2cce8b0..1cfd5f6 100644
> --- lib/MC/MCParser/AsmParser.cpp
> +++ lib/MC/MCParser/AsmParser.cpp
> @@ -4174,8 +4174,10 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc,
> std::string &AsmString,
>
>      // Emit everything up to the immediate/expression.  If the previous rewrite
>      // was a size directive, then this has already been done.
> -    if (PrevKind != AOK_SizeDirective)
> +    if (PrevKind != AOK_SizeDirective) {
> +      assert(Loc >= Start);
>        OS << StringRef(Start, Loc - Start);
> +    }
>      PrevKind = Kind;
>
>      // Skip the original expression.
> ---------------------------------------------------------------------------------
>
>
> I hope that's enough info to debug :)
>
>
> FYI The bug was hard to debug as a substantial part of memory was
> corrupted (including EBPs, return addresses etc)
> so I propose something like this to prevent such bugs from re-appearing:
> ---------------------------------------------------------------------------------
> diff --git include/llvm/ADT/StringRef.h include/llvm/ADT/StringRef.h
> index 1e21d92..077c056 100644
> --- include/llvm/ADT/StringRef.h
> +++ include/llvm/ADT/StringRef.h
> @@ -84,6 +84,7 @@ namespace llvm {
>        : Data(data), Length(length) {
>          assert((data || length == 0) &&
>          "StringRef cannot be built from a NULL argument with non-null length");
> +        assert(length < 0x80000000 && "length looks suspicious");
>        }
>
>      /// Construct a string ref from an std::string.
> ---------------------------------------------------------------------------------
>
> 2013/2/15 Timur Iskhodzhanov <timurrrr at google.com>:
>> FYI this crashes on my Windows bot.
>>
>> I'll update with the details when I reproduce locally.
>>
>> 2013/2/13 Chad Rosier <mcrosier at apple.com>:
>>> Author: mcrosier
>>> Date: Wed Feb 13 12:38:58 2013
>>> New Revision: 175063
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=175063&view=rev
>>> Log:
>>> [ms-inline-asm] Use an array_pod_sort, rather than a std:sort.
>>>
>>>
>>> Modified:
>>>     llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>>
>>> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=175063&r1=175062&r2=175063&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
>>> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Feb 13 12:38:58 2013
>>> @@ -13,6 +13,7 @@
>>>
>>>  #include "llvm/ADT/APFloat.h"
>>>  #include "llvm/ADT/SmallString.h"
>>> +#include "llvm/ADT/STLExtras.h"
>>>  #include "llvm/ADT/StringMap.h"
>>>  #include "llvm/ADT/Twine.h"
>>>  #include "llvm/MC/MCAsmInfo.h"
>>> @@ -4029,8 +4030,14 @@ bool AsmParser::ParseDirectiveMSAlign(SM
>>>    return false;
>>>  }
>>>
>>> -bool AsmStringSort (AsmRewrite A, AsmRewrite B) {
>>> -  return A.Loc.getPointer() < B.Loc.getPointer();
>>> +static int RewritesSort (const void *A, const void *B) {
>>> +  const AsmRewrite *AsmRewriteA = static_cast<const AsmRewrite*>(A);
>>> +  const AsmRewrite *AsmRewriteB = static_cast<const AsmRewrite*>(B);
>>> +  if (AsmRewriteA->Loc.getPointer() < AsmRewriteB->Loc.getPointer())
>>> +    return -1;
>>> +  if (AsmRewriteB->Loc.getPointer() < AsmRewriteA->Loc.getPointer())
>>> +    return 1;
>>> +  return 0;
>>>  }
>>>
>>>  bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
>>> @@ -4157,7 +4164,7 @@ bool AsmParser::ParseMSInlineAsm(void *A
>>>    AsmRewriteKind PrevKind = AOK_Imm;
>>>    raw_string_ostream OS(AsmStringIR);
>>>    const char *Start = SrcMgr.getMemoryBuffer(0)->getBufferStart();
>>> -  std::sort (AsmStrRewrites.begin(), AsmStrRewrites.end(), AsmStringSort);
>>> +  array_pod_sort (AsmStrRewrites.begin(), AsmStrRewrites.end(), RewritesSort);
>>>    for (SmallVectorImpl<struct AsmRewrite>::iterator
>>>           I = AsmStrRewrites.begin(), E = AsmStrRewrites.end(); I != E; ++I) {
>>>      const char *Loc = (*I).Loc.getPointer();
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
0. Program arguments: D:/src/llvm-trunk/build/bin/Debug/clang.exe -cc1 -triple i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name windowsh_pass.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -g -coverage-file D:\src\asan\win_tests\windowsh_pass.o -resource-dir D:/src/llvm-trunk/build/bin/Debug\..\lib\clang\3.3 -internal-isystem D:/src/llvm-trunk/build/bin/Debug/../lib/clang/3.3/include -internal-isystem c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE -internal-isystem c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE -internal-isystem c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include -std=c++11 -fdeprecated-macro -ferror-limit 19 -fmessage-length 0 -mstackrealign -fno-rtti -fms-extensions -fms-compatibility -fmsc-version=1300 -fdelayed-template-parsing -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -backend-option -vectorize-loops -cxx-abi microsoft -o windowsh_pass.o -x c++ windowsh_pass.cpp
1. c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h:809:1: current parser token '}'
2. c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h:801:1: parsing function body 'Int64ShllMod32'
3. c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h:801:1: in compound statement ('{}')
0x5A3189EB (0x0000000A 0x00000000 0x03D4B12C 0x5A3E6237), _get_pgmptr() + 0x21B bytes(s)
0x5A3F4F2E (0x03D4B650 0x03D4B140 0x03D4A6EC 0x778F1D18), abort() + 0x1E bytes(s)
0x5A3E6237 (0x02B59F30 0x02B59868 0x00000057 0x03D4B154), _wassert() + 0xB77 bytes(s)
0x002776F9 (0x0598311B 0xFFFFFFF6 0x03D4BD10 0x03D4B680), llvm::StringRef::StringRef() + 0x79 bytes(s), include\llvm\adt\stringref.h, line 87 + 0x26 byte(s)
0x006D3729 (0x00046DBD 0x03D4B8F4 0x03D4B928 0x03D4B91C), `anonymous namespace'::AsmParser::ParseMSInlineAsm() + 0xA69 bytes(s), lib\mc\mcparser\asmparser.cpp, line 4179 + 0x1F byte(s)
0x01A99AFA (0x03D4C134 0x00046DBD 0x00046DC6 0x05A5FD50), clang::Sema::ActOnMSAsmStmt() + 0x6EA bytes(s), tools\clang\lib\sema\semastmtasm.cpp, line 655 + 0x6E byte(s)
0x01375D62 (0x03D4C134 0x00046DBD 0x03D4C1F4 0x03D4E20C), clang::Parser::ParseMicrosoftAsmStatement() + 0x402 bytes(s), tools\clang\lib\parse\parsestmt.cpp, line 1776 + 0x38 byte(s)
0x01375F12 (0x03D4C134 0x03D4C177 0x03D4C258 0xCCCCCCCC), clang::Parser::ParseAsmStatement() + 0xC2 bytes(s), tools\clang\lib\parse\parsestmt.cpp, line 1805 + 0x10 byte(s)
0x01370C13 (0x03D4C21C 0x03D4C464 0x00000000 0x00000000), clang::Parser::ParseStatementOrDeclarationAfterAttributes() + 0x603 bytes(s), tools\clang\lib\parse\parsestmt.cpp, line 233 + 0x13 byte(s)
0x013704D7 (0x03D4C290 0x03D4C464 0x00000000 0x00000000), clang::Parser::ParseStatementOrDeclaration() + 0x67 bytes(s), tools\clang\lib\parse\parsestmt.cpp, line 93
0x01372C86 (0x03D4C5A4 0x00000000 0x03D4C7F8 0x03D4E20C), clang::Parser::ParseCompoundStatementBody() + 0x3D6 bytes(s), tools\clang\lib\parse\parsestmt.cpp, line 822 + 0x1A byte(s)
0x01376AF9 (0x05EEF9F0 0x03D4C6D0 0x03D4CDE0 0x03D4E20C), clang::Parser::ParseFunctionStatementBody() + 0xD9 bytes(s), tools\clang\lib\parse\parsestmt.cpp, line 2000
0x01325EA3 (0x03D4C970 0x03D4C87C 0x03D4C950 0x03D4CE74), clang::Parser::ParseFunctionDefinition() + 0xA03 bytes(s), tools\clang\lib\parse\parser.cpp, line 1089 + 0x16 byte(s)
0x01355319 (0x03D4D3E4 0x03D4CEAC 0x00000000 0x00000001), clang::Parser::ParseDeclGroup() + 0x179 bytes(s), tools\clang\lib\parse\parsedecl.cpp, line 1458 + 0x22 byte(s)
0x01325328 (0x03D4D3E4 0x03D4D428 0x03D4CEAC 0x00000003), clang::Parser::ParseDeclOrFunctionDefInternal() + 0x298 bytes(s), tools\clang\lib\parse\parser.cpp, line 867 + 0x18 byte(s)
0x01325429 (0x03D4D3E4 0x03D4D428 0x00000000 0x00000003), clang::Parser::ParseDeclarationOrFunctionDefinition() + 0x89 bytes(s), tools\clang\lib\parse\parser.cpp, line 883 + 0x1B byte(s)
0x01324B1D (0x03D4D3E4 0x03D4D428 0x00000000 0x03D4D568), clang::Parser::ParseExternalDeclaration() + 0x8BD bytes(s), tools\clang\lib\parse\parser.cpp, line 748 + 0x16 byte(s)
0x0133CDAD (0x03D4D5A0 0x00000000 0x03D4D6FC 0xCCCCCCCC), clang::Parser::ParseLinkage() + 0x31D bytes(s), tools\clang\lib\parse\parsedeclcxx.cpp, line 325
0x013252F3 (0x03D4DAD8 0x03D4DB1C 0x03D4D5A0 0x00000003), clang::Parser::ParseDeclOrFunctionDefInternal() + 0x263 bytes(s), tools\clang\lib\parse\parser.cpp, line 863 + 0xE byte(s)
0x01325429 (0x03D4DAD8 0x03D4DB1C 0x00000000 0x00000003), clang::Parser::ParseDeclarationOrFunctionDefinition() + 0x89 bytes(s), tools\clang\lib\parse\parser.cpp, line 883 + 0x1B byte(s)
0x01324B1D (0x03D4DAD8 0x03D4DB1C 0x00000000 0x03D4DC5C), clang::Parser::ParseExternalDeclaration() + 0x8BD bytes(s), tools\clang\lib\parse\parser.cpp, line 748 + 0x16 byte(s)
0x0133CDAD (0x03D4DC94 0x00000000 0x03D4DDF0 0xCCCCCCCC), clang::Parser::ParseLinkage() + 0x31D bytes(s), tools\clang\lib\parse\parsedeclcxx.cpp, line 325
0x013252F3 (0x03D4E1C4 0x03D4E1D8 0x03D4DC94 0x00000003), clang::Parser::ParseDeclOrFunctionDefInternal() + 0x263 bytes(s), tools\clang\lib\parse\parser.cpp, line 863 + 0xE byte(s)
0x01325429 (0x03D4E1C4 0x03D4E1D8 0x00000000 0x00000003), clang::Parser::ParseDeclarationOrFunctionDefinition() + 0x89 bytes(s), tools\clang\lib\parse\parser.cpp, line 883 + 0x1B byte(s)
0x01324B1D (0x03D4E1C4 0x03D4E1D8 0x00000000 0x03D4E290), clang::Parser::ParseExternalDeclaration() + 0x8BD bytes(s), tools\clang\lib\parse\parser.cpp, line 748 + 0x16 byte(s)
0x013241E8 (0x03D4E248 0x03D4E530 0x03D4E2A0 0x059BCFD0), clang::Parser::ParseTopLevelDecl() + 0x138 bytes(s), tools\clang\lib\parse\parser.cpp, line 560 + 0x12 byte(s)
0x01321499 (0x059B9C10 0x00000000 0x00000000 0x03D4E538), clang::ParseAST() + 0x1B9 bytes(s), tools\clang\lib\parse\parseast.cpp, line 133 + 0xC byte(s)
0x011EE56D (0x03D4E5B4 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC), clang::ASTFrontendAction::ExecuteAction() + 0xED bytes(s), tools\clang\lib\frontend\frontendaction.cpp, line 466 + 0x30 byte(s)
0x00F99D7B (0x03D4E560 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC), clang::CodeGenAction::ExecuteAction() + 0x33B bytes(s), tools\clang\lib\codegen\codegenaction.cpp, line 424
0x011EE1AC (0x03D4E654 0x03D4F780 0xCCCCCCCC 0xCCCCCCCC), clang::FrontendAction::Execute() + 0xAC bytes(s), tools\clang\lib\frontend\frontendaction.cpp, line 374 + 0xF byte(s)
0x011DECD1 (0x05963D28 0x03D4EC14 0xCCCCCCCC 0xCCCCCCCC), clang::CompilerInstance::ExecuteAction() + 0x281 bytes(s), tools\clang\lib\frontend\compilerinstance.cpp, line 688
0x00F57375 (0x0409F228 0x03D4FBBC 0x0409FF30 0x0409FE88), clang::ExecuteCompilerInvocation() + 0x305 bytes(s), tools\clang\lib\frontendtool\executecompilerinvocation.cpp, line 235 + 0x11 byte(s)
0x00283902 (0x03D4F788 0x03D4F864 0x0409A8A8 0x0027145B), cc1_main() + 0x2F2 bytes(s), tools\clang\tools\driver\cc1_main.cpp, line 98 + 0xE byte(s)
0x00273A69 (0x00000039 0x0409A140 0x040922C8 0xC53EFD34), main() + 0x149 bytes(s), tools\clang\tools\driver\driver.cpp, line 358 + 0x45 byte(s)
0x01F795DF (0x03D4FC20 0x75B733AA 0x7EFDE000 0x03D4FC60), __tmainCRTStartup() + 0x1BF bytes(s), f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c, line 555 + 0x19 byte(s)
0x01F7940F (0x7EFDE000 0x03D4FC60 0x778C9EF2 0x7EFDE000), mainCRTStartup() + 0xF bytes(s), f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c, line 371
0x75B733AA (0x7EFDE000 0x7F63A19B 0x00000000 0x00000000), BaseThreadInitThunk() + 0x12 bytes(s)
0x778C9EF2 (0x01F79400 0x7EFDE000 0x00000000 0x00000000), RtlInitializeExceptionChain() + 0x63 bytes(s)
0x778C9EC5 (0x01F79400 0x7EFDE000 0x00000000 0x00000000), RtlInitializeExceptionChain() + 0x36 bytes(s)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.3
Target: i686-pc-win32
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: C:/Users/timurrrr/AppData/Local/Temp/windowsh_pass-036380.cpp
clang: note: diagnostic msg: C:/Users/timurrrr/AppData/Local/Temp/windowsh_pass-036380.sh
clang: note: diagnostic msg:

********************



More information about the llvm-commits mailing list