r305087 - support operator keywords used in Windows SDK

Keane, Erich via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 9 15:01:08 PDT 2017


Thanks, I didn't notice that one.  Looking into it.

-Erich

-----Original Message-----
From: Evgenii Stepanov [mailto:eugeni.stepanov at gmail.com] 
Sent: Friday, June 9, 2017 3:00 PM
To: Keane, Erich <erich.keane at intel.com>
Cc: cfe-commits <cfe-commits at lists.llvm.org>
Subject: Re: r305087 - support operator keywords used in Windows SDK

Hi,

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/5571/steps/check-clang%20ubsan/logs/stdio

tools/clang/lib/Parse/ParseExprCXX.cpp:383:26: runtime error:
reference binding to null pointer of type 'clang::IdentifierInfo'
    #0 0x5313046 in
clang::Parser::ParseOptionalCXXScopeSpecifier(clang::CXXScopeSpec&,
clang::OpaquePtr<clang::QualType>, bool, bool*, bool, clang::IdentifierInfo**, bool)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseExprCXX.cpp:383:21
    #1 0x52d3dc7 in
clang::Parser::ParseDirectDeclarator(clang::Declarator&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDecl.cpp:5433:7
    #2 0x52d349d in
clang::Parser::ParseDeclaratorInternal(clang::Declarator&, void
(clang::Parser::*)(clang::Declarator&))
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDecl.cpp:5254:7
    #3 0x52ee74c in
clang::Parser::ParseCXXMemberDeclaratorBeforeInitializer(clang::Declarator&,
clang::VirtSpecifiers&, clang::ActionResult<clang::Expr*, true>&,
clang::Parser::LateParsedAttrList&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:2248:5
    #4 0x52efaef in
clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier,
clang::AttributeList*, clang::Parser::ParsedTemplateInfo const&,
clang::ParsingDeclRAIIObject*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:2619:7
    #5 0x52f147a in
clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&,
clang::Parser::ParsedAttributesWithRange&, clang::TypeSpecifierType,
clang::Decl*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:3079:12
    #6 0x52ed276 in
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation,
clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&,
unsigned int, clang::Decl*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:3250:7
    #7 0x52eb9ad in
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:1910:7
    #8 0x52c8c41 in
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDecl.cpp:3588:7
    #9 0x52ef702 in
clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier,
clang::AttributeList*, clang::Parser::ParsedTemplateInfo const&,
clang::ParsingDeclRAIIObject*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:2550:3
    #10 0x52f147a in
clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&,
clang::Parser::ParsedAttributesWithRange&, clang::TypeSpecifierType,
clang::Decl*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:3079:12
    #11 0x52ed276 in
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation,
clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&,
unsigned int, clang::Decl*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:3250:7
    #12 0x52eb9ad in
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:1910:7
    #13 0x52c8c41 in
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDecl.cpp:3588:7
    #14 0x52a89c6 in
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:912:3
    #15 0x52a8542 in
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:993:12
    #16 0x52a7b5f in
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:843:12
    #17 0x52a6ebc in
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:611:12
    #18 0x52a6bb4 in
clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/Parser.cpp:533:26
    #19 0x52a1dfb in clang::ParseAST(clang::Sema&, bool, bool)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseAST.cpp:146:23
    #20 0x3eaa4a2 in clang::FrontendAction::Execute()
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:894:8
    #21 0x3e3bf44 in
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:970:11
    #22 0x402ef7c in
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:249:25
    #23 0xe59ece in cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/tools/driver/cc1_main.cpp:221:13
    #24 0xe4d223 in ExecuteCC1Tool(llvm::ArrayRef<char const*>,
llvm::StringRef)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/tools/driver/driver.cpp:299:12
    #25 0xe4c5f3 in main
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/tools/driver/driver.cpp:380:12

On Fri, Jun 9, 2017 at 9:29 AM, Erich Keane via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> Author: erichkeane
> Date: Fri Jun  9 11:29:35 2017
> New Revision: 305087
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305087&view=rev
> Log:
> support operator keywords used in Windows SDK
>
> to support operator keywords used in Windows SDK, alter token type 
> when seen in system headers
>
> Hello, I submitted D33505 to address this problem, but the proposal 
> was rejected as too big a hammer.
> This change will allow clang to parse the WindowsSDK header <query.h> 
> which uses the operator name "or" as a field name. Treat cpp operator 
> keywords as ordinary identifiers inside the Microsoft headers, but 
> treat them as usual in the user's program.
>
> Original Submitter: Melanie Blower (mibintc)
>
> Differential Revision: https://reviews.llvm.org/D33782
>
>
>
> Added:
>     cfe/trunk/test/Headers/ms-cppoperkey.cpp
>     cfe/trunk/test/Headers/ms-cppoperkey1.cpp
>     cfe/trunk/test/Headers/ms-cppoperkey2.cpp
> Modified:
>     cfe/trunk/lib/Lex/Preprocessor.cpp
>
> Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp
> ?rev=305087&r1=305086&r2=305087&view=diff
> ======================================================================
> ========
> --- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
> +++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Jun  9 11:29:35 2017
> @@ -580,7 +580,11 @@ IdentifierInfo *Preprocessor::LookUpIden
>
>    // Update the token info (identifier info and appropriate token kind).
>    Identifier.setIdentifierInfo(II);
> -  Identifier.setKind(II->getTokenID());
> +  if (getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() &&
> +      getSourceManager().isInSystemHeader(Identifier.getLocation()))
> +    Identifier.setKind(clang::tok::identifier);
> +  else
> +    Identifier.setKind(II->getTokenID());
>
>    return II;
>  }
>
> Added: cfe/trunk/test/Headers/ms-cppoperkey.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-cppoperk
> ey.cpp?rev=305087&view=auto 
> ======================================================================
> ========
> --- cfe/trunk/test/Headers/ms-cppoperkey.cpp (added)
> +++ cfe/trunk/test/Headers/ms-cppoperkey.cpp Fri Jun  9 11:29:35 2017
> @@ -0,0 +1,16 @@
> +// RUN: %clang_cc1 \
> +// RUN:     -fms-compatibility -x c++-cpp-output \
> +// RUN:     -ffreestanding -fsyntax-only -Werror \
> +// RUN:     %s -verify
> +// expected-no-diagnostics
> +# 1 "t.cpp"
> +# 1 "query.h" 1 3
> +// MS header <query.h> uses operator keyword as field name.
> +// Compile without syntax errors.
> +struct tagRESTRICTION
> +  {
> +   union _URes
> +     {
> +       int or; // Note use of cpp operator token
> +     } res;
> +  };
>
> Added: cfe/trunk/test/Headers/ms-cppoperkey1.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-cppoperk
> ey1.cpp?rev=305087&view=auto 
> ======================================================================
> ========
> --- cfe/trunk/test/Headers/ms-cppoperkey1.cpp (added)
> +++ cfe/trunk/test/Headers/ms-cppoperkey1.cpp Fri Jun  9 11:29:35 2017
> @@ -0,0 +1,27 @@
> +// RUN: %clang_cc1 \
> +// RUN:     -fms-compatibility -x c++-cpp-output \
> +// RUN:     -ffreestanding -fsyntax-only -Werror \
> +// RUN:     %s -verify
> +
> +
> +# 1 "t.cpp"
> +# 1 "query.h" 1 3 4
> +// MS header <query.h> uses operator keyword as field name.
> +// Compile without syntax errors.
> +struct tagRESTRICTION
> +  {
> +   union _URes
> +     {
> +       int or; // Note use of cpp operator token
> +     } res;
> +  };
> +   ;
> +
> +int aa ( int x)
> +{
> +  // In system header code, treat operator keyword as identifier.
> +  if ( // expected-note{{to match this '('}}
> +    x>1 or x<0) return 1; // expected-error{{expected ')'}}
> +  else return 0;
> +}
> +
>
> Added: cfe/trunk/test/Headers/ms-cppoperkey2.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-cppoperk
> ey2.cpp?rev=305087&view=auto 
> ======================================================================
> ========
> --- cfe/trunk/test/Headers/ms-cppoperkey2.cpp (added)
> +++ cfe/trunk/test/Headers/ms-cppoperkey2.cpp Fri Jun  9 11:29:35 2017
> @@ -0,0 +1,11 @@
> +// RUN: %clang_cc1  -triple x86_64-pc-win32 -fms-compatibility \
> +// RUN:     -ffreestanding -fsyntax-only -Werror  %s -verify
> +// RUN: %clang_cc1 \
> +// RUN:     -ffreestanding -fsyntax-only -Werror  %s -verify
> +// expected-no-diagnostics
> +int bb ( int x)
> +{
> +  // In user code, treat operator keyword as operator keyword.
> +  if ( x>1 or x<0) return 1;
> +  else return 0;
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list