[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation
Hahnfeld updated this revision to Diff 162543. Hahnfeld added a comment. Based on libc++ I guessed some more macros that may be needed on macOS and Windows. As I can't test myself if somebody else could report if this change is regressing CUDA support on these platforms. https://reviews.llvm.org/D50845 Files: lib/Frontend/InitPreprocessor.cpp test/Preprocessor/aux-triple.c test/SemaCUDA/builtins.cu Index: test/SemaCUDA/builtins.cu === --- test/SemaCUDA/builtins.cu +++ test/SemaCUDA/builtins.cu @@ -12,8 +12,8 @@ // RUN: -aux-triple x86_64-unknown-unknown \ // RUN: -fsyntax-only -verify %s -#if !(defined(__amd64__) && defined(__PTX__)) -#error "Expected to see preprocessor macros from both sides of compilation." +#if !defined(__x86_64__) +#error "Expected to see preprocessor macros from the host." #endif void hf() { Index: test/Preprocessor/aux-triple.c === --- /dev/null +++ test/Preprocessor/aux-triple.c @@ -0,0 +1,62 @@ +// Ensure that Clang sets some very basic target defines based on -aux-triple. + +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s +// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s + +// CUDA: +// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none -aux-triple powerpc64le-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s \ +// RUN: -check-prefixes NVPTX64,PPC64,LINUX,LINUX-CPP +// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none -aux-triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s \ +// RUN: -check-prefixes NVPTX64,X86_64,LINUX,LINUX-CPP + +// OpenMP: +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \ +// RUN: -aux-triple powerpc64le-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,PPC64,LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \ +// RUN: -aux-triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,X86_64,LINUX %s +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \ +// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \ +// RUN: -aux-triple powerpc64le-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s \ +// RUN: -check-prefixes NVPTX64,PPC64,LINUX,LINUX-CPP +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \ +// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \ +// RUN: -aux-triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s \ +// RUN: -check-prefixes NVPTX64,X86_64,LINUX,LINUX-CPP + +// NONE-NOT:#define _GNU_SOURCE +// LINUX-CPP:#define _GNU_SOURCE 1 + +// NVPTX64:#define _LP64 1 + +// NONE-NOT:#define __ELF__ +// LINUX:#define __ELF__ 1 + +// NVPTX64:#define __LP64__ 1 +// NVPTX64:#define __NVPTX__ 1 +// NVPTX64:#define __PTX__ 1 + +// NONE-NOT:#define __linux__ +// LINUX:#define __linux__ 1 + +// NONE-NOT:#define __powerpc64__ +// PPC64:#define __powerpc64__ 1 + +// NONE-NOT:#define __x86_64__ +// X86_64:#define __x86_64__ 1 Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -1099,6 +1099,44 @@ TI.getTargetDefines(LangOpts, Builder); } +/// Initialize macros based on AuxTargetInfo. +static void InitializePredefinedAuxMacros(const TargetInfo &AuxTI, + const LangOptions &LangOpts, + MacroBuilder &Builder) { + auto AuxTriple = AuxTI.getTriple(); + + // Define basic target macros needed by at least bits/wordsize.h and + // bits/mathinline.h + switch (AuxTriple.getArch()) { + case llvm::Triple::x86_64: +Builder.defineMacro("__x86_64__"); +break; + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: +Builder.defineMacro("__powerpc64__"); +break; + default: +break; + } + + // libc++ needs to find out the object file format and threading API. + if (AuxTriple.getOS() == llvm::Triple::Linux) { +Builder.defineMacro("__ELF__"); +Builder.defineMacro("__linux__"); +// Used in features.h. If this is omitted, math.h doesn't declare float +// versions of the funct
[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation
Hahnfeld added a comment. In https://reviews.llvm.org/D50845#1212643, @tra wrote: > Please keep an eye on CUDA buildbot > http://lab.llvm.org:8011/builders/clang-cuda-build. > It runs fair amount of tests with libc++ and handful of libstdc++ versions > and may a canary if these changes break something. I just tested locally and `std::remainder` fails with CUDA 8.0.44 when compiling for `c++11` or later - both with and without this patch. My guess is that this version has a bug because all tests pass with CUDA 9.2.88. I'll land this change now and watch the buildbot for any problems, thanks. https://reviews.llvm.org/D50845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r340681 - [CUDA/OpenMP] Define only some host macros during device compilation
Author: hahnfeld Date: Sat Aug 25 06:42:40 2018 New Revision: 340681 URL: http://llvm.org/viewvc/llvm-project?rev=340681&view=rev Log: [CUDA/OpenMP] Define only some host macros during device compilation When compiling CUDA or OpenMP device code Clang parses header files that expect certain predefined macros from the host architecture. To make this work the compiler passes the host triple via the -aux-triple argument and (until now) pulls in all macros for that "auxiliary triple" unconditionally. However this results in defines like __SSE_MATH__ that will trigger inline assembly making use of the "advertised" target features. See the discussion of D47849 and PR38464 for a detailed explanation of the encountered problems. Instead of blacklisting "known bad" examples this patch starts adding defines that are needed for certain headers like bits/wordsize.h and bits/mathinline.h. The disadvantage of this approach is that it decouples the definitions from their target toolchain. However in my opinion it's more important to keep definitions for one header close together. For one this will include a clear documentation why these particular defines are needed. Furthermore it simplifies maintenance because adding defines for a new header or support for a new aux-triple only needs to touch one piece of code. Differential Revision: https://reviews.llvm.org/D50845 Added: cfe/trunk/test/Preprocessor/aux-triple.c Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/SemaCUDA/builtins.cu Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=340681&r1=340680&r2=340681&view=diff == --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Sat Aug 25 06:42:40 2018 @@ -1099,6 +1099,44 @@ static void InitializePredefinedMacros(c TI.getTargetDefines(LangOpts, Builder); } +/// Initialize macros based on AuxTargetInfo. +static void InitializePredefinedAuxMacros(const TargetInfo &AuxTI, + const LangOptions &LangOpts, + MacroBuilder &Builder) { + auto AuxTriple = AuxTI.getTriple(); + + // Define basic target macros needed by at least bits/wordsize.h and + // bits/mathinline.h + switch (AuxTriple.getArch()) { + case llvm::Triple::x86_64: +Builder.defineMacro("__x86_64__"); +break; + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: +Builder.defineMacro("__powerpc64__"); +break; + default: +break; + } + + // libc++ needs to find out the object file format and threading API. + if (AuxTriple.getOS() == llvm::Triple::Linux) { +Builder.defineMacro("__ELF__"); +Builder.defineMacro("__linux__"); +// Used in features.h. If this is omitted, math.h doesn't declare float +// versions of the functions in bits/mathcalls.h. +if (LangOpts.CPlusPlus) + Builder.defineMacro("_GNU_SOURCE"); + } else if (AuxTriple.isOSDarwin()) { +Builder.defineMacro("__APPLE__"); +Builder.defineMacro("__MACH__"); + } else if (AuxTriple.isOSWindows()) { +Builder.defineMacro("_WIN32"); +if (AuxTriple.isWindowsGNUEnvironment()) + Builder.defineMacro("__MINGW32__"); + } +} + /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. This returns true on error. /// @@ -1120,13 +1158,9 @@ void clang::InitializePreprocessor( // Install things like __POWERPC__, __GNUC__, etc into the macro table. if (InitOpts.UsePredefines) { -// FIXME: This will create multiple definitions for most of the predefined -// macros. This is not the right way to handle this. -if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo()) - InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, - Builder); - InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder); +if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo()) + InitializePredefinedAuxMacros(*PP.getAuxTargetInfo(), LangOpts, Builder); // Install definitions to make Objective-C++ ARC work well with various // C++ Standard Library implementations. Added: cfe/trunk/test/Preprocessor/aux-triple.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/aux-triple.c?rev=340681&view=auto == --- cfe/trunk/test/Preprocessor/aux-triple.c (added) +++ cfe/trunk/test/Preprocessor/aux-triple.c Sat Aug 25 06:42:40 2018 @@ -0,0 +1,62 @@ +// Ensure that Clang sets some very basic target defines based on -aux-triple. + +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-f
[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation
This revision was automatically updated to reflect the committed changes. Closed by commit rL340681: [CUDA/OpenMP] Define only some host macros during device compilation (authored by Hahnfeld, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D50845?vs=162543&id=162545#toc Repository: rL LLVM https://reviews.llvm.org/D50845 Files: cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/Preprocessor/aux-triple.c cfe/trunk/test/SemaCUDA/builtins.cu Index: cfe/trunk/lib/Frontend/InitPreprocessor.cpp === --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp @@ -1099,6 +1099,44 @@ TI.getTargetDefines(LangOpts, Builder); } +/// Initialize macros based on AuxTargetInfo. +static void InitializePredefinedAuxMacros(const TargetInfo &AuxTI, + const LangOptions &LangOpts, + MacroBuilder &Builder) { + auto AuxTriple = AuxTI.getTriple(); + + // Define basic target macros needed by at least bits/wordsize.h and + // bits/mathinline.h + switch (AuxTriple.getArch()) { + case llvm::Triple::x86_64: +Builder.defineMacro("__x86_64__"); +break; + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: +Builder.defineMacro("__powerpc64__"); +break; + default: +break; + } + + // libc++ needs to find out the object file format and threading API. + if (AuxTriple.getOS() == llvm::Triple::Linux) { +Builder.defineMacro("__ELF__"); +Builder.defineMacro("__linux__"); +// Used in features.h. If this is omitted, math.h doesn't declare float +// versions of the functions in bits/mathcalls.h. +if (LangOpts.CPlusPlus) + Builder.defineMacro("_GNU_SOURCE"); + } else if (AuxTriple.isOSDarwin()) { +Builder.defineMacro("__APPLE__"); +Builder.defineMacro("__MACH__"); + } else if (AuxTriple.isOSWindows()) { +Builder.defineMacro("_WIN32"); +if (AuxTriple.isWindowsGNUEnvironment()) + Builder.defineMacro("__MINGW32__"); + } +} + /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. This returns true on error. /// @@ -1120,13 +1158,9 @@ // Install things like __POWERPC__, __GNUC__, etc into the macro table. if (InitOpts.UsePredefines) { -// FIXME: This will create multiple definitions for most of the predefined -// macros. This is not the right way to handle this. -if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo()) - InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, - Builder); - InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder); +if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo()) + InitializePredefinedAuxMacros(*PP.getAuxTargetInfo(), LangOpts, Builder); // Install definitions to make Objective-C++ ARC work well with various // C++ Standard Library implementations. Index: cfe/trunk/test/Preprocessor/aux-triple.c === --- cfe/trunk/test/Preprocessor/aux-triple.c +++ cfe/trunk/test/Preprocessor/aux-triple.c @@ -0,0 +1,62 @@ +// Ensure that Clang sets some very basic target defines based on -aux-triple. + +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s +// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,NONE %s + +// CUDA: +// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none -aux-triple powerpc64le-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s \ +// RUN: -check-prefixes NVPTX64,PPC64,LINUX,LINUX-CPP +// RUN: %clang_cc1 -x cuda -E -dM -ffreestanding < /dev/null \ +// RUN: -triple nvptx64-none-none -aux-triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s \ +// RUN: -check-prefixes NVPTX64,X86_64,LINUX,LINUX-CPP + +// OpenMP: +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \ +// RUN: -aux-triple powerpc64le-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines -check-prefixes NVPTX64,PPC64,LINUX %s +// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null \ +// RUN: -fopenmp -fopenmp-is-device -triple nvptx64-none-none \ +// RUN: -aux-triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines -chec
[PATCH] D51258: Extract parseBindID method
steveire created this revision. Herald added a subscriber: cfe-commits. Repository: rC Clang https://reviews.llvm.org/D51258 Files: include/clang/ASTMatchers/Dynamic/Parser.h lib/ASTMatchers/Dynamic/Parser.cpp Index: lib/ASTMatchers/Dynamic/Parser.cpp === --- lib/ASTMatchers/Dynamic/Parser.cpp +++ lib/ASTMatchers/Dynamic/Parser.cpp @@ -359,6 +359,43 @@ return parseMatcherExpressionImpl(NameToken, Value); } +bool Parser::parseBindID(std::string &BindID, TokenInfo &CloseToken) { + // Parse .bind("foo") + assert(Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period); + Tokenizer->consumeNextToken(); // consume the period. + const TokenInfo BindToken = Tokenizer->consumeNextToken(); + if (BindToken.Kind == TokenInfo::TK_CodeCompletion) { +addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1)); +return false; + } + + const TokenInfo OpenToken = Tokenizer->consumeNextToken(); + const TokenInfo IDToken = Tokenizer->consumeNextToken(); + CloseToken = Tokenizer->consumeNextToken(); + + // TODO: We could use different error codes for each/some to be more + // explicit about the syntax error. + if (BindToken.Kind != TokenInfo::TK_Ident || + BindToken.Text != TokenInfo::ID_Bind) { +Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr); +return false; + } + if (OpenToken.Kind != TokenInfo::TK_OpenParen) { +Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr); +return false; + } + if (IDToken.Kind != TokenInfo::TK_Literal || !IDToken.Value.isString()) { +Error->addError(IDToken.Range, Error->ET_ParserMalformedBindExpr); +return false; + } + if (CloseToken.Kind != TokenInfo::TK_CloseParen) { +Error->addError(CloseToken.Range, Error->ET_ParserMalformedBindExpr); +return false; + } + BindID = IDToken.Value.getString(); + return true; +} + /// Parse and validate a matcher expression. /// \return \c true on success, in which case \c Value has the matcher parsed. /// If the input is malformed, or some argument has an error, it @@ -425,38 +462,9 @@ std::string BindID; if (Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period) { -// Parse .bind("foo") -Tokenizer->consumeNextToken(); // consume the period. -const TokenInfo BindToken = Tokenizer->consumeNextToken(); -if (BindToken.Kind == TokenInfo::TK_CodeCompletion) { - addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1)); +TokenInfo CloseToken; +if (!parseBindID(BindID, CloseToken)) return false; -} - -const TokenInfo OpenToken = Tokenizer->consumeNextToken(); -const TokenInfo IDToken = Tokenizer->consumeNextToken(); -const TokenInfo CloseToken = Tokenizer->consumeNextToken(); - -// TODO: We could use different error codes for each/some to be more -// explicit about the syntax error. -if (BindToken.Kind != TokenInfo::TK_Ident || -BindToken.Text != TokenInfo::ID_Bind) { - Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr); - return false; -} -if (OpenToken.Kind != TokenInfo::TK_OpenParen) { - Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr); - return false; -} -if (IDToken.Kind != TokenInfo::TK_Literal || !IDToken.Value.isString()) { - Error->addError(IDToken.Range, Error->ET_ParserMalformedBindExpr); - return false; -} -if (CloseToken.Kind != TokenInfo::TK_CloseParen) { - Error->addError(CloseToken.Range, Error->ET_ParserMalformedBindExpr); - return false; -} -BindID = IDToken.Value.getString(); } if (!Ctor) Index: include/clang/ASTMatchers/Dynamic/Parser.h === --- include/clang/ASTMatchers/Dynamic/Parser.h +++ include/clang/ASTMatchers/Dynamic/Parser.h @@ -234,6 +234,7 @@ const NamedValueMap *NamedValues, Diagnostics *Error); + bool parseBindID(std::string &BindID, TokenInfo &endToken); bool parseExpressionImpl(VariantValue *Value); bool parseMatcherExpressionImpl(const TokenInfo &NameToken, VariantValue *Value); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51259: Allow binding to NamedValue resulting from let expression
steveire created this revision. Herald added a subscriber: cfe-commits. Repository: rC Clang https://reviews.llvm.org/D51259 Files: lib/ASTMatchers/Dynamic/Parser.cpp unittests/ASTMatchers/Dynamic/ParserTest.cpp Index: unittests/ASTMatchers/Dynamic/ParserTest.cpp === --- unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -359,6 +359,44 @@ Comps[2].MatcherDecl); } +TEST(ParserTest, ParseBindOnLet) { + + auto NamedValues = getTestNamedValues(); + + Diagnostics Error; + + { +llvm::Optional topLevelLetBinding( +Parser::parseMatcherExpression("hasParamA.bind(\"parmABinding\")", + nullptr, &NamedValues, &Error)); +EXPECT_EQ("", Error.toStringFull()); +auto M = topLevelLetBinding->unconditionalConvertTo(); + +EXPECT_TRUE(matchAndVerifyResultTrue( +"void foo(int a);", M, +llvm::make_unique>("parmABinding"))); +EXPECT_TRUE(matchAndVerifyResultFalse( +"void foo(int b);", M, +llvm::make_unique>("parmABinding"))); + } + + { +llvm::Optional nestedLetBinding( +Parser::parseMatcherExpression( +"functionDecl(hasParamA.bind(\"parmABinding\"))", nullptr, +&NamedValues, &Error)); +EXPECT_EQ("", Error.toStringFull()); +auto M = nestedLetBinding->unconditionalConvertTo(); + +EXPECT_TRUE(matchAndVerifyResultTrue( +"void foo(int a);", M, +llvm::make_unique>("parmABinding"))); +EXPECT_TRUE(matchAndVerifyResultFalse( +"void foo(int b);", M, +llvm::make_unique>("parmABinding"))); + } +} + } // end anonymous namespace } // end namespace dynamic } // end namespace ast_matchers Index: lib/ASTMatchers/Dynamic/Parser.cpp === --- lib/ASTMatchers/Dynamic/Parser.cpp +++ lib/ASTMatchers/Dynamic/Parser.cpp @@ -339,8 +339,28 @@ if (const VariantValue NamedValue = NamedValues ? NamedValues->lookup(NameToken.Text) : VariantValue()) { - *Value = NamedValue; - return true; + + if (Tokenizer->nextTokenKind() != TokenInfo::TK_Period) { +*Value = NamedValue; +return true; + } + + std::string BindID; + TokenInfo EndToken; + if (!parseBindID(BindID, EndToken)) +return false; + + assert(NamedValue.isMatcher()); + llvm::Optional Result = + NamedValue.getMatcher().getSingleMatcher(); + if (Result.hasValue()) { +llvm::Optional Bound = Result->tryBind(BindID); +if (Bound.hasValue()) { + *Value = VariantMatcher::SingleMatcher(*Bound); + return true; +} + } + return false; } // If the syntax is correct and the name is not a matcher either, report // unknown named value. Index: unittests/ASTMatchers/Dynamic/ParserTest.cpp === --- unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -359,6 +359,44 @@ Comps[2].MatcherDecl); } +TEST(ParserTest, ParseBindOnLet) { + + auto NamedValues = getTestNamedValues(); + + Diagnostics Error; + + { +llvm::Optional topLevelLetBinding( +Parser::parseMatcherExpression("hasParamA.bind(\"parmABinding\")", + nullptr, &NamedValues, &Error)); +EXPECT_EQ("", Error.toStringFull()); +auto M = topLevelLetBinding->unconditionalConvertTo(); + +EXPECT_TRUE(matchAndVerifyResultTrue( +"void foo(int a);", M, +llvm::make_unique>("parmABinding"))); +EXPECT_TRUE(matchAndVerifyResultFalse( +"void foo(int b);", M, +llvm::make_unique>("parmABinding"))); + } + + { +llvm::Optional nestedLetBinding( +Parser::parseMatcherExpression( +"functionDecl(hasParamA.bind(\"parmABinding\"))", nullptr, +&NamedValues, &Error)); +EXPECT_EQ("", Error.toStringFull()); +auto M = nestedLetBinding->unconditionalConvertTo(); + +EXPECT_TRUE(matchAndVerifyResultTrue( +"void foo(int a);", M, +llvm::make_unique>("parmABinding"))); +EXPECT_TRUE(matchAndVerifyResultFalse( +"void foo(int b);", M, +llvm::make_unique>("parmABinding"))); + } +} + } // end anonymous namespace } // end namespace dynamic } // end namespace ast_matchers Index: lib/ASTMatchers/Dynamic/Parser.cpp === --- lib/ASTMatchers/Dynamic/Parser.cpp +++ lib/ASTMatchers/Dynamic/Parser.cpp @@ -339,8 +339,28 @@ if (const VariantValue NamedValue = NamedValues ? NamedValues->lookup(NameToken.Text) : VariantValue()) { - *Value = NamedValue; - return true; + + if (Tokenizer->nextTokenKind() != TokenInfo::TK_Period) { +
[PATCH] D51260: Extract runCommandsInFile method
steveire created this revision. Herald added a subscriber: cfe-commits. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51260 Files: clang-query/tool/ClangQuery.cpp Index: clang-query/tool/ClangQuery.cpp === --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -58,6 +58,24 @@ cl::value_desc("file"), cl::cat(ClangQueryCategory)); +int runCommandsInFile(const char* exeName, std::string const& fileName, QuerySession& QS) +{ +std::ifstream Input(fileName.c_str()); +if (!Input.is_open()) { + llvm::errs() << exeName << ": cannot open " << fileName << "\n"; + return 1; +} +while (Input.good()) { + std::string Line; + std::getline(Input, Line); + + QueryRef Q = QueryParser::parse(Line, QS); + if (!Q->run(llvm::outs(), QS)) +return 1; +} +return 0; +} + int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); @@ -84,19 +102,8 @@ } } else if (!CommandFiles.empty()) { for (auto I = CommandFiles.begin(), E = CommandFiles.end(); I != E; ++I) { - std::ifstream Input(I->c_str()); - if (!Input.is_open()) { -llvm::errs() << argv[0] << ": cannot open " << *I << "\n"; -return 1; - } - while (Input.good()) { -std::string Line; -std::getline(Input, Line); - -QueryRef Q = QueryParser::parse(Line, QS); -if (!Q->run(llvm::outs(), QS)) - return 1; - } + if (auto err = runCommandsInFile(argv[0], *I, QS)) +return err; } } else { LineEditor LE("clang-query"); Index: clang-query/tool/ClangQuery.cpp === --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -58,6 +58,24 @@ cl::value_desc("file"), cl::cat(ClangQueryCategory)); +int runCommandsInFile(const char* exeName, std::string const& fileName, QuerySession& QS) +{ +std::ifstream Input(fileName.c_str()); +if (!Input.is_open()) { + llvm::errs() << exeName << ": cannot open " << fileName << "\n"; + return 1; +} +while (Input.good()) { + std::string Line; + std::getline(Input, Line); + + QueryRef Q = QueryParser::parse(Line, QS); + if (!Q->run(llvm::outs(), QS)) +return 1; +} +return 0; +} + int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); @@ -84,19 +102,8 @@ } } else if (!CommandFiles.empty()) { for (auto I = CommandFiles.begin(), E = CommandFiles.end(); I != E; ++I) { - std::ifstream Input(I->c_str()); - if (!Input.is_open()) { -llvm::errs() << argv[0] << ": cannot open " << *I << "\n"; -return 1; - } - while (Input.good()) { -std::string Line; -std::getline(Input, Line); - -QueryRef Q = QueryParser::parse(Line, QS); -if (!Q->run(llvm::outs(), QS)) - return 1; - } + if (auto err = runCommandsInFile(argv[0], *I, QS)) +return err; } } else { LineEditor LE("clang-query"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51261: Add preload option to clang-query
steveire created this revision. Herald added a subscriber: cfe-commits. This allows loading a file with pre-defined let commands for example. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51261 Files: clang-query/tool/ClangQuery.cpp Index: clang-query/tool/ClangQuery.cpp === --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -58,6 +58,11 @@ cl::value_desc("file"), cl::cat(ClangQueryCategory)); +static cl::opt PreloadFile( +"preload", +cl::desc("Preload commands from file and start interactive mode"), +cl::value_desc("file"), cl::cat(ClangQueryCategory)); + int runCommandsInFile(const char* exeName, std::string const& fileName, QuerySession& QS) { std::ifstream Input(fileName.c_str()); @@ -86,6 +91,12 @@ return 1; } + if ((!Commands.empty() || !CommandFiles.empty()) && !PreloadFile.empty()) { +llvm::errs() << argv[0] + << ": cannot specify both -c or -f with --preload\n"; +return 1; + } + ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); std::vector> ASTs; @@ -106,6 +117,10 @@ return err; } } else { +if (!PreloadFile.empty()) { + if (auto err = runCommandsInFile(argv[0], PreloadFile, QS)) +return err; +} LineEditor LE("clang-query"); LE.setListCompleter([&QS](StringRef Line, size_t Pos) { return QueryParser::complete(Line, Pos, QS); Index: clang-query/tool/ClangQuery.cpp === --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -58,6 +58,11 @@ cl::value_desc("file"), cl::cat(ClangQueryCategory)); +static cl::opt PreloadFile( +"preload", +cl::desc("Preload commands from file and start interactive mode"), +cl::value_desc("file"), cl::cat(ClangQueryCategory)); + int runCommandsInFile(const char* exeName, std::string const& fileName, QuerySession& QS) { std::ifstream Input(fileName.c_str()); @@ -86,6 +91,12 @@ return 1; } + if ((!Commands.empty() || !CommandFiles.empty()) && !PreloadFile.empty()) { +llvm::errs() << argv[0] + << ": cannot specify both -c or -f with --preload\n"; +return 1; + } + ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); std::vector> ASTs; @@ -106,6 +117,10 @@ return err; } } else { +if (!PreloadFile.empty()) { + if (auto err = runCommandsInFile(argv[0], PreloadFile, QS)) +return err; +} LineEditor LE("clang-query"); LE.setListCompleter([&QS](StringRef Line, size_t Pos) { return QueryParser::complete(Line, Pos, QS); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33029: [clang-format] add option for dangling parenthesis
zroug added a comment. I'd also like to note that this is the code style preferred by most modern code formatters that I know of and use: - rustfmt for rust code - prettier for javascript code - black for python code https://reviews.llvm.org/D33029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)
Wawha added a comment. Hi klimek, do you have time to take a look again to this patch? Is my last patch ok for you? best regards, François Repository: rC Clang https://reviews.llvm.org/D44609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50101: [asan] Update a vector's storage annotation during destruction.
bobsayshilol added a comment. Pinging this as it's been "Ready to Land" for a while and I want to check that that's not because I've forgotten to do something? Repository: rCXX libc++ https://reviews.llvm.org/D50101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51262: Implement P0553 and P0556
mclow.lists created this revision. mclow.lists added reviewers: EricWF, ldionne. Herald added a subscriber: christof. LWG adopted https://wg21.link/P0553 in Rapperswil, and suggested minor changes to https://wg21.link/P0556. They kind of go together; for example, `ispow2` is easily implemented using `popcount` - and they share a bunch of infastructure. I don't recommend landing this until P0556 is approved, but when I implemented one, the other was easy. None of this stuff will be constexpr on Windows, because the underlying primitives are not constexpr on Windows. Sorry for the large-ish diff, but (like span) it's 85%+ tests. https://reviews.llvm.org/D51262 Files: include/bit test/libcxx/numerics/bit/bitops.count/countl_one.pass.cpp test/libcxx/numerics/bit/bitops.count/countl_zero.pass.cpp test/libcxx/numerics/bit/bitops.count/countr_one.pass.cpp test/libcxx/numerics/bit/bitops.count/countr_zero.pass.cpp test/libcxx/numerics/bit/bitops.count/popcount.pass.cpp test/libcxx/numerics/bit/bitops.rot/rotl.pass.cpp test/libcxx/numerics/bit/bitops.rot/rotr.pass.cpp test/std/numerics/bit/bit.pow.two/ceil2.fail.cpp test/std/numerics/bit/bit.pow.two/ceil2.pass.cpp test/std/numerics/bit/bit.pow.two/floor2.fail.cpp test/std/numerics/bit/bit.pow.two/floor2.pass.cpp test/std/numerics/bit/bit.pow.two/ispow2.fail.cpp test/std/numerics/bit/bit.pow.two/ispow2.pass.cpp test/std/numerics/bit/bit.pow.two/log2p1.fail.cpp test/std/numerics/bit/bit.pow.two/log2p1.pass.cpp test/std/numerics/bit/bitops.count/countl_one.fail.cpp test/std/numerics/bit/bitops.count/countl_one.pass.cpp test/std/numerics/bit/bitops.count/countl_zero.fail.cpp test/std/numerics/bit/bitops.count/countl_zero.pass.cpp test/std/numerics/bit/bitops.count/countr_one.fail.cpp test/std/numerics/bit/bitops.count/countr_one.pass.cpp test/std/numerics/bit/bitops.count/countr_zero.fail.cpp test/std/numerics/bit/bitops.count/countr_zero.pass.cpp test/std/numerics/bit/bitops.count/popcount.fail.cpp test/std/numerics/bit/bitops.count/popcount.pass.cpp test/std/numerics/bit/bitops.rot/rotl.fail.cpp test/std/numerics/bit/bitops.rot/rotl.pass.cpp test/std/numerics/bit/bitops.rot/rotr.fail.cpp test/std/numerics/bit/bitops.rot/rotr.pass.cpp test/std/numerics/bit/nothing_to_do.pass.cpp Index: test/std/numerics/bit/nothing_to_do.pass.cpp === --- test/std/numerics/bit/nothing_to_do.pass.cpp +++ test/std/numerics/bit/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +int main() +{ +} Index: test/std/numerics/bit/bitops.rot/rotr.pass.cpp === --- test/std/numerics/bit/bitops.rot/rotr.pass.cpp +++ test/std/numerics/bit/bitops.rot/rotr.pass.cpp @@ -0,0 +1,137 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// template +// constexpr int rotr(T x, unsigned int s) noexcept; + +// Remarks: This function shall not participate in overload resolution unless +// T is an unsigned integer type + +#include +#include + +#include "test_macros.h" + +template +constexpr bool constexpr_test() +{ + const T max = std::numeric_limits::max(); + + return std::rotr(T(128), 0) == T(128) + && std::rotr(T(128), 1) == T( 64) + && std::rotr(T(128), 2) == T( 32) + && std::rotr(T(128), 3) == T( 16) + && std::rotr(T(128), 4) == T( 8) + && std::rotr(T(128), 5) == T( 4) + && std::rotr(T(128), 6) == T( 2) + && std::rotr(T(128), 7) == T( 1) + && std::rotr(max, 0) == max + && std::rotr(max, 1) == max + && std::rotr(max, 2) == max + && std::rotr(max, 3) == max + && std::rotr(max, 4) == max + && std::rotr(max, 5) == max + && std::rotr(max, 6) == max + && std::rotr(max, 7) == max + ; +} + + +template +void runtime_test() +{ + ASSERT_SAME_TYPE(T, decltype(std::rotr(T(0), 0))); + ASSERT_NOEXCEPT( std::rotr(T(0), 0)); + const T max = std::numeric_limits::max(); + const T val = std::numeric_limits::max() - 1; + + const T uppers [] = { + max, // not used + max - max, // 000 .. 0 + max - (max >> 1), // 800 .. 0 + max - (max >> 2), // C00 .. 0 + max - (max >> 3), // E00 .. 0 + max - (max >> 4), //
[PATCH] D51262: Implement P0553 and P0556
mclow.lists added a comment. I should also mention that as a conforming extension, I have implemented the non-numeric bit operations for `std::byte` https://reviews.llvm.org/D51262 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51187: Thread safety analysis: Warn on double (un-)lock of scoped capability
aaronpuchert updated this revision to Diff 162562. aaronpuchert added a comment. Use Locked flag to determine whether to unlock on destruction Instead of unlocking the mutexes that are still available while not complaining about those that aren't, we use the status of the scoped capability to determine whether to unlock the underlying mutexes. This way we will attempt to unlock the mutex even if the user unlocked it manually, warning if it is no longer available, and we will not attempt to unlock if we are already released, hence warning if it is manually acquired again. Repository: rC Clang https://reviews.llvm.org/D51187 Files: lib/Analysis/ThreadSafety.cpp test/SemaCXX/warn-thread-safety-analysis.cpp Index: test/SemaCXX/warn-thread-safety-analysis.cpp === --- test/SemaCXX/warn-thread-safety-analysis.cpp +++ test/SemaCXX/warn-thread-safety-analysis.cpp @@ -1729,7 +1729,7 @@ MutexLock mulock_a(&mu1); MutexLock mulock_b(&mu1); // \ // expected-warning {{acquiring mutex 'mu1' that is already held}} - } + } // expected-warning {{releasing mutex 'mu1' that was not held}} void foo4() { MutexLock mulock1(&mu1), mulock2(&mu2); @@ -2580,6 +2580,8 @@ void test3(); void test4(); void test5(); + void test6(); + void test7(); }; @@ -2605,18 +2607,29 @@ void Foo::test4() { ReleasableMutexLock rlock(&mu_); rlock.Release(); - rlock.Release(); // expected-warning {{releasing mutex 'mu_' that was not held}} + rlock.Release(); // expected-warning {{releasing mutex 'rlock' that was not held}} } void Foo::test5() { ReleasableMutexLock rlock(&mu_); if (c) { rlock.Release(); } // no warning on join point for managed lock. - rlock.Release(); // expected-warning {{releasing mutex 'mu_' that was not held}} + rlock.Release(); // expected-warning {{releasing mutex 'rlock' that was not held}} } +void Foo::test6() { + ReleasableMutexLock rlock(&mu_); + mu_.Unlock(); +} // expected-warning {{releasing mutex 'mu_' that was not held}} + +void Foo::test7() { + ReleasableMutexLock rlock(&mu_); + rlock.Release(); + mu_.Lock(); // expected-note {{mutex acquired here}} +} // expected-warning {{mutex 'mu_' is still held at the end of function}} + } // end namespace ReleasableScopedLock @@ -2704,37 +2717,33 @@ void doubleUnlock() { RelockableExclusiveMutexLock scope(&mu); scope.Unlock(); - scope.Unlock(); // expected-warning {{releasing mutex 'mu' that was not held}} + scope.Unlock(); // expected-warning {{releasing mutex 'scope' that was not held}} } void doubleLock1() { RelockableExclusiveMutexLock scope(&mu); - scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}} + scope.Lock(); // expected-warning {{acquiring mutex 'scope' that is already held}} } void doubleLock2() { RelockableExclusiveMutexLock scope(&mu); scope.Unlock(); scope.Lock(); - scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}} + scope.Lock(); // expected-warning {{acquiring mutex 'scope' that is already held}} } void directUnlock() { RelockableExclusiveMutexLock scope(&mu); mu.Unlock(); - // Debatable that there is no warning. Currently we don't track in the scoped - // object whether it is active, but just check if the contained locks can be - // reacquired. Here they can, because mu has been unlocked manually. - scope.Lock(); -} + scope.Lock(); // expected-warning {{acquiring mutex 'scope' that is already held}} +} // expected-warning {{releasing mutex 'mu' that was not held}} void directRelock() { RelockableExclusiveMutexLock scope(&mu); scope.Unlock(); - mu.Lock(); - // Similarly debatable that there is no warning. - scope.Unlock(); -} + mu.Lock(); // expected-note {{mutex acquired here}} + scope.Unlock(); // expected-warning {{releasing mutex 'scope' that was not held}} +} // expected-warning {{mutex 'mu' is still held at the end of function}} // Doesn't make a lot of sense, just making sure there is no crash. void destructLock() { Index: lib/Analysis/ThreadSafety.cpp === --- lib/Analysis/ThreadSafety.cpp +++ lib/Analysis/ThreadSafety.cpp @@ -144,11 +144,11 @@ ThreadSafetyHandler &Handler) const = 0; virtual void handleLock(FactSet &FSet, FactManager &FactMan, const FactEntry &entry, ThreadSafetyHandler &Handler, - StringRef DiagKind) const = 0; + StringRef DiagKind) = 0; virtual void handleUnlock(FactSet &FSet, FactManager &FactMan, const CapabilityExpr &Cp, SourceLocation UnlockLoc, bool FullyRemove, ThreadSafetyHandler &Handler, -StringRef DiagKind) const = 0; +StringRef DiagKind) = 0;
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
hfinkel added a comment. In https://reviews.llvm.org/D37624#1211748, @apazos wrote: > Hello folks, is there a plan to merge this feature still? There's still a desire for the underlying functionality. We still need, as I recall, to figure out what's supposed to happen for C++ functions. https://reviews.llvm.org/D37624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33029: [clang-format] add option for dangling parenthesis
owenpan added a comment. @stringham Here is what I did to run the unit tests: cd build make FormatTests tools/clang/unittests/Format/FormatTests https://reviews.llvm.org/D33029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33029: [clang-format] add option for dangling parenthesis
stringham added a comment. @djasper can you give some direction here? Would you be okay with me extending the BracketAlignmentStyle option? What do I need to do to get this change merged? https://reviews.llvm.org/D33029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51265: Headers: fix collisions with .h files of other projects
andrewrk created this revision. andrewrk added reviewers: eli.friedman, krememek, ddunbar, lattner. andrewrk added a project: clang. Herald added a subscriber: cfe-commits. stdarg.h: - va_list - macos _va_list.h was duplicately defining va_list. Fixed by this ifndef _VA_LIST_T - additionally define _VA_LIST_DEFINED because glibc stdio.h was duplicately defining va_list stddef.h - ptrdiff_t - wrap in _PTRDIFF_T_DEFINED to protect against mingw defining it twice - size_t - protections against collisions with mingw - wchar_t - protections against duplicate definition with mingw All of these came up in real world scenarios when using libclang to parse .h files in the Zig project. These are the patches that Zig has on top of libclang headers, and if this patch is merged, then Zig project will be tracking clang trunk. Repository: rC Clang https://reviews.llvm.org/D51265 Files: lib/Headers/stdarg.h lib/Headers/stddef.h Index: lib/Headers/stddef.h === --- lib/Headers/stddef.h +++ lib/Headers/stddef.h @@ -48,7 +48,12 @@ #if !__has_feature(modules) #define _PTRDIFF_T #endif + +#if !defined(_PTRDIFF_T_DEFINED) typedef __PTRDIFF_TYPE__ ptrdiff_t; +#define _PTRDIFF_T_DEFINED +#endif + #endif #undef __need_ptrdiff_t #endif /* defined(__need_ptrdiff_t) */ @@ -59,7 +64,23 @@ #if !__has_feature(modules) #define _SIZE_T #endif + +#if !defined(_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DEFINED) +#if !defined(_BSD_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DECLARED) typedef __SIZE_TYPE__ size_t; +#define _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED +#define _BSD_SIZE_T_DEFINED_ +#define _SIZE_T_DECLARED +#endif +#endif +#endif +#endif + + + #endif #undef __need_size_t #endif /*defined(__need_size_t) */ @@ -87,7 +108,21 @@ #define _WCHAR_T_DEFINED #endif #endif + +#if !defined(__INT_WCHAR_T_H) +#if !defined(_GCC_WCHAR_T) +#if !defined(_WCHAR_T_DECLARED) +#if !defined(_WCHAR_T_DEFINED) +#define __INT_WCHAR_T_H +#define _GCC_WCHAR_T +#define _WCHAR_T_DECLARED +#define _WCHAR_T_DEFINED typedef __WCHAR_TYPE__ wchar_t; +#endif +#endif +#endif +#endif + #endif #endif #undef __need_wchar_t Index: lib/Headers/stdarg.h === --- lib/Headers/stdarg.h +++ lib/Headers/stdarg.h @@ -27,9 +27,11 @@ #define __STDARG_H #ifndef _VA_LIST +#ifndef _VA_LIST_T typedef __builtin_va_list va_list; #define _VA_LIST #endif +#endif #define va_start(ap, param) __builtin_va_start(ap, param) #define va_end(ap) __builtin_va_end(ap) #define va_arg(ap, type)__builtin_va_arg(ap, type) @@ -46,6 +48,7 @@ #ifndef __GNUC_VA_LIST #define __GNUC_VA_LIST 1 typedef __builtin_va_list __gnuc_va_list; +#define _VA_LIST_DEFINED #endif #endif /* __STDARG_H */ Index: lib/Headers/stddef.h === --- lib/Headers/stddef.h +++ lib/Headers/stddef.h @@ -48,7 +48,12 @@ #if !__has_feature(modules) #define _PTRDIFF_T #endif + +#if !defined(_PTRDIFF_T_DEFINED) typedef __PTRDIFF_TYPE__ ptrdiff_t; +#define _PTRDIFF_T_DEFINED +#endif + #endif #undef __need_ptrdiff_t #endif /* defined(__need_ptrdiff_t) */ @@ -59,7 +64,23 @@ #if !__has_feature(modules) #define _SIZE_T #endif + +#if !defined(_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DEFINED) +#if !defined(_BSD_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DECLARED) typedef __SIZE_TYPE__ size_t; +#define _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED +#define _BSD_SIZE_T_DEFINED_ +#define _SIZE_T_DECLARED +#endif +#endif +#endif +#endif + + + #endif #undef __need_size_t #endif /*defined(__need_size_t) */ @@ -87,7 +108,21 @@ #define _WCHAR_T_DEFINED #endif #endif + +#if !defined(__INT_WCHAR_T_H) +#if !defined(_GCC_WCHAR_T) +#if !defined(_WCHAR_T_DECLARED) +#if !defined(_WCHAR_T_DEFINED) +#define __INT_WCHAR_T_H +#define _GCC_WCHAR_T +#define _WCHAR_T_DECLARED +#define _WCHAR_T_DEFINED typedef __WCHAR_TYPE__ wchar_t; +#endif +#endif +#endif +#endif + #endif #endif #undef __need_wchar_t Index: lib/Headers/stdarg.h === --- lib/Headers/stdarg.h +++ lib/Headers/stdarg.h @@ -27,9 +27,11 @@ #define __STDARG_H #ifndef _VA_LIST +#ifndef _VA_LIST_T typedef __builtin_va_list va_list; #define _VA_LIST #endif +#endif #define va_start(ap, param) __builtin_va_start(ap, param) #define va_end(ap) __builtin_va_end(ap) #define va_arg(ap, type)__builtin_va_arg(ap, type) @@ -46,6 +48,7 @@ #ifndef __GNUC_VA_LIST #define __GNUC_VA_LIST 1 typedef __builtin_va_list __gnuc_va_list; +#define _VA_LIST_DEFINED #endif #endif /* __STDARG_H */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51265: Headers: fix collisions with .h files of other projects
Qix- added inline comments. Comment at: lib/Headers/stdarg.h:30 #ifndef _VA_LIST +#ifndef _VA_LIST_T typedef __builtin_va_list va_list; Super nit-picky but you could condense this a bit by using ``` #if !defined(_VA_LIST) && !defined(_VA_LIST_T) ``` and a single `#endif` (revert the addition of line 34). It's arguably easier to understand intent instead of adding another level of nesting. Same thing goes for the other two sections. Just a suggestion. Repository: rC Clang https://reviews.llvm.org/D51265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51265: Headers: fix collisions with .h files of other projects
andrewrk updated this revision to Diff 162574. andrewrk added a comment. Addressed review feedback Repository: rC Clang https://reviews.llvm.org/D51265 Files: lib/Headers/stdarg.h lib/Headers/stddef.h Index: lib/Headers/stddef.h === --- lib/Headers/stddef.h +++ lib/Headers/stddef.h @@ -48,7 +48,12 @@ #if !__has_feature(modules) #define _PTRDIFF_T #endif + +#if !defined(_PTRDIFF_T_DEFINED) typedef __PTRDIFF_TYPE__ ptrdiff_t; +#define _PTRDIFF_T_DEFINED +#endif + #endif #undef __need_ptrdiff_t #endif /* defined(__need_ptrdiff_t) */ @@ -59,7 +64,23 @@ #if !__has_feature(modules) #define _SIZE_T #endif + +#if !defined(_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DEFINED) +#if !defined(_BSD_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DECLARED) typedef __SIZE_TYPE__ size_t; +#define _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED +#define _BSD_SIZE_T_DEFINED_ +#define _SIZE_T_DECLARED +#endif +#endif +#endif +#endif + + + #endif #undef __need_size_t #endif /*defined(__need_size_t) */ @@ -87,7 +108,21 @@ #define _WCHAR_T_DEFINED #endif #endif + +#if !defined(__INT_WCHAR_T_H) +#if !defined(_GCC_WCHAR_T) +#if !defined(_WCHAR_T_DECLARED) +#if !defined(_WCHAR_T_DEFINED) +#define __INT_WCHAR_T_H +#define _GCC_WCHAR_T +#define _WCHAR_T_DECLARED +#define _WCHAR_T_DEFINED typedef __WCHAR_TYPE__ wchar_t; +#endif +#endif +#endif +#endif + #endif #endif #undef __need_wchar_t Index: lib/Headers/stdarg.h === --- lib/Headers/stdarg.h +++ lib/Headers/stdarg.h @@ -26,7 +26,7 @@ #ifndef __STDARG_H #define __STDARG_H -#ifndef _VA_LIST +#if !defined(_VA_LIST) && !defined(_VA_LIST_T) typedef __builtin_va_list va_list; #define _VA_LIST #endif @@ -46,6 +46,7 @@ #ifndef __GNUC_VA_LIST #define __GNUC_VA_LIST 1 typedef __builtin_va_list __gnuc_va_list; +#define _VA_LIST_DEFINED #endif #endif /* __STDARG_H */ Index: lib/Headers/stddef.h === --- lib/Headers/stddef.h +++ lib/Headers/stddef.h @@ -48,7 +48,12 @@ #if !__has_feature(modules) #define _PTRDIFF_T #endif + +#if !defined(_PTRDIFF_T_DEFINED) typedef __PTRDIFF_TYPE__ ptrdiff_t; +#define _PTRDIFF_T_DEFINED +#endif + #endif #undef __need_ptrdiff_t #endif /* defined(__need_ptrdiff_t) */ @@ -59,7 +64,23 @@ #if !__has_feature(modules) #define _SIZE_T #endif + +#if !defined(_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DEFINED) +#if !defined(_BSD_SIZE_T_DEFINED_) +#if !defined(_SIZE_T_DECLARED) typedef __SIZE_TYPE__ size_t; +#define _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED +#define _BSD_SIZE_T_DEFINED_ +#define _SIZE_T_DECLARED +#endif +#endif +#endif +#endif + + + #endif #undef __need_size_t #endif /*defined(__need_size_t) */ @@ -87,7 +108,21 @@ #define _WCHAR_T_DEFINED #endif #endif + +#if !defined(__INT_WCHAR_T_H) +#if !defined(_GCC_WCHAR_T) +#if !defined(_WCHAR_T_DECLARED) +#if !defined(_WCHAR_T_DEFINED) +#define __INT_WCHAR_T_H +#define _GCC_WCHAR_T +#define _WCHAR_T_DECLARED +#define _WCHAR_T_DEFINED typedef __WCHAR_TYPE__ wchar_t; +#endif +#endif +#endif +#endif + #endif #endif #undef __need_wchar_t Index: lib/Headers/stdarg.h === --- lib/Headers/stdarg.h +++ lib/Headers/stdarg.h @@ -26,7 +26,7 @@ #ifndef __STDARG_H #define __STDARG_H -#ifndef _VA_LIST +#if !defined(_VA_LIST) && !defined(_VA_LIST_T) typedef __builtin_va_list va_list; #define _VA_LIST #endif @@ -46,6 +46,7 @@ #ifndef __GNUC_VA_LIST #define __GNUC_VA_LIST 1 typedef __builtin_va_list __gnuc_va_list; +#define _VA_LIST_DEFINED #endif #endif /* __STDARG_H */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51268: [libc++] Implement P0487R1 - Fixing operator>>(basic_istream&, CharT*)
lichray created this revision. lichray added reviewers: mclow.lists, ldionne. Herald added a reviewer: EricWF. Herald added a subscriber: christof. Avoid buffer overflow by replacing the pointer interface with an array reference interface in C++2a. Tentatively ready on Batavia2018. https://wg21.link/lwg2499 https://wg21.link/p0487 Repository: rCXX libc++ https://reviews.llvm.org/D51268 Files: include/istream test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp Index: test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp === --- test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp +++ test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp @@ -50,6 +50,17 @@ assert(!is.fail()); assert(std::string(s) == "abcdefghijk"); } +#if TEST_STD_VER > 17 +{ +testbuf sb(" abcdefghijk"); +std::istream is(&sb); +char s[4]; +is >> s; +assert(!is.eof()); +assert(!is.fail()); +assert(std::string(s) == "abc"); +} +#endif { testbuf sb(L" abcdefghijk"); std::wistream is(&sb); @@ -71,6 +82,17 @@ assert(std::wstring(s) == L"abcdefghijk"); assert(is.width() == 0); } +#if TEST_STD_VER > 17 +{ +testbuf sb(L" abcdefghijk"); +std::wistream is(&sb); +wchar_t s[4]; +is >> s; +assert(!is.eof()); +assert(!is.fail()); +assert(std::wstring(s) == L"abc"); +} +#endif { testbuf sb(" abcdefghijk"); std::istream is(&sb); @@ -82,4 +104,15 @@ assert(std::string(s) == ""); assert(is.width() == 0); } +#if TEST_STD_VER > 17 +{ +testbuf sb(" abcdefghijk"); +std::istream is(&sb); +char s[1]; +is >> s; +assert(!is.eof()); +assert( is.fail()); +assert(std::string(s) == ""); +} +#endif } Index: test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp === --- test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp +++ test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp @@ -61,6 +61,17 @@ assert(std::string((char*)s) == "abc"); assert(is.width() == 0); } +#if TEST_STD_VER > 17 +{ +testbuf sb(" abcdefghijk"); +std::istream is(&sb); +unsigned char s[4]; +is >> s; +assert(!is.eof()); +assert(!is.fail()); +assert(std::string((char*)s) == "abc"); +} +#endif { testbuf sb(" abcdefghijk"); std::istream is(&sb); @@ -82,4 +93,15 @@ assert(std::string((char*)s) == ""); assert(is.width() == 0); } +#if TEST_STD_VER > 17 +{ +testbuf sb(" abcdefghijk"); +std::istream is(&sb); +unsigned char s[1]; +is >> s; +assert(!is.eof()); +assert( is.fail()); +assert(std::string((char*)s) == ""); +} +#endif } Index: test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp === --- test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp +++ test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp @@ -61,6 +61,17 @@ assert(std::string((char*)s) == "abc"); assert(is.width() == 0); } +#if TEST_STD_VER > 17 +{ +testbuf sb(" abcdefghijk"); +std::istream is(&sb); +signed char s[4]; +is >> s; +assert(!is.eof()); +assert(!is.fail()); +assert(std::string((char*)s) == "abc"); +} +#endif { testbuf sb(" abcdefghijk"); std::istream is(&sb); @@ -82,4 +93,15 @@ assert(std::string((char*)s) == ""); assert(is.width() == 0); } +#if TEST_STD_VER > 17 +{ +testbuf sb(" abcdefghijk"); +std::istream is(&sb); +signed char s[1]; +is >> s; +assert(!is.eof()); +assert( is.fail()); +assert(std::string((char*)s) == ""); +} +#endif } Inde
r340696 - [index] Introduce 'ProtocolInterface' as part of SymbolPropertySet
Author: akirtzidis Date: Sat Aug 25 23:27:23 2018 New Revision: 340696 URL: http://llvm.org/viewvc/llvm-project?rev=340696&view=rev Log: [index] Introduce 'ProtocolInterface' as part of SymbolPropertySet This is useful to directly infer that a method or property is from a protocol interface at the point of the symbol occurrences. Modified: cfe/trunk/include/clang/Index/IndexSymbol.h cfe/trunk/lib/Index/IndexSymbol.cpp cfe/trunk/test/Index/Core/external-source-symbol-attr.m cfe/trunk/test/Index/Core/index-source.m Modified: cfe/trunk/include/clang/Index/IndexSymbol.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=340696&r1=340695&r2=340696&view=diff == --- cfe/trunk/include/clang/Index/IndexSymbol.h (original) +++ cfe/trunk/include/clang/Index/IndexSymbol.h Sat Aug 25 23:27:23 2018 @@ -75,7 +75,7 @@ enum class SymbolSubKind : uint8_t { UsingValue, }; -typedef uint8_t SymbolPropertySet; +typedef uint16_t SymbolPropertySet; /// Set of properties that provide additional info about a symbol. enum class SymbolProperty : SymbolPropertySet { Generic = 1 << 0, @@ -86,8 +86,10 @@ enum class SymbolProperty : SymbolProper IBOutletCollection= 1 << 5, GKInspectable = 1 << 6, Local = 1 << 7, + /// Symbol is part of a protocol interface. + ProtocolInterface = 1 << 8, }; -static const unsigned SymbolPropertyBitNum = 8; +static const unsigned SymbolPropertyBitNum = 9; /// Set of roles that are attributed to symbol occurrences. /// Modified: cfe/trunk/lib/Index/IndexSymbol.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=340696&r1=340695&r2=340696&view=diff == --- cfe/trunk/lib/Index/IndexSymbol.cpp (original) +++ cfe/trunk/lib/Index/IndexSymbol.cpp Sat Aug 25 23:27:23 2018 @@ -96,6 +96,9 @@ SymbolInfo index::getSymbolInfo(const De if (isFunctionLocalSymbol(D)) { Info.Properties |= (SymbolPropertySet)SymbolProperty::Local; } + if (isa(D->getDeclContext())) { +Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface; + } if (const TagDecl *TD = dyn_cast(D)) { switch (TD->getTagKind()) { @@ -519,6 +522,7 @@ void index::applyForEachSymbolProperty(S APPLY_FOR_PROPERTY(IBOutletCollection); APPLY_FOR_PROPERTY(GKInspectable); APPLY_FOR_PROPERTY(Local); + APPLY_FOR_PROPERTY(ProtocolInterface); #undef APPLY_FOR_PROPERTY } @@ -539,6 +543,7 @@ void index::printSymbolProperties(Symbol case SymbolProperty::IBOutletCollection: OS << "IBColl"; break; case SymbolProperty::GKInspectable: OS << "GKI"; break; case SymbolProperty::Local: OS << "local"; break; +case SymbolProperty::ProtocolInterface: OS << "protocol"; break; } }); } Modified: cfe/trunk/test/Index/Core/external-source-symbol-attr.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/external-source-symbol-attr.m?rev=340696&r1=340695&r2=340696&view=diff == --- cfe/trunk/test/Index/Core/external-source-symbol-attr.m (original) +++ cfe/trunk/test/Index/Core/external-source-symbol-attr.m Sat Aug 25 23:27:23 2018 @@ -87,7 +87,7 @@ void test2(I3 *i3, id prot2, S [i3 meth2]; // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth2 | c:@CM@modname@objc(cs)I3(im)meth2 | [prot2 meth]; - // CHECK: [[@LINE-1]]:10 | instance-method/Swift | meth | c:@M@modname@objc(pl)ExtProt2(im)meth | + // CHECK: [[@LINE-1]]:10 | instance-method(protocol)/Swift | meth | c:@M@modname@objc(pl)ExtProt2(im)meth | some = SomeEnumFirst; // CHECK: [[@LINE-1]]:10 | enumerator/Swift | SomeEnumFirst | c:@M@modname@E@SomeEnum@SomeEnumFirst | } Modified: cfe/trunk/test/Index/Core/index-source.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.m?rev=340696&r1=340695&r2=340696&view=diff == --- cfe/trunk/test/Index/Core/index-source.m (original) +++ cfe/trunk/test/Index/Core/index-source.m Sat Aug 25 23:27:23 2018 @@ -474,12 +474,12 @@ void testImplicitProperties(ImplicitProp @end @protocol Prot3 // CHECK: [[@LINE]]:11 | protocol/ObjC | Prot3 | [[PROT3_USR:.*]] | | Decl | --(void)meth; +-(void)meth; // CHECK: [[@LINE]]:8 | instance-method(protocol)/ObjC | meth | [[PROT3_meth_USR:.*]] | -[Prot3 meth] | Decl,Dyn,RelChild | @end void test_rec1() { id o1; - [o1 meth]; // CHECK: [[@LINE]]:7 | instance-method/ObjC | meth | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 3 + [o1 meth]; // CHECK: [[@LINE]]:7 | instance-method(protocol)/ObjC | meth | [[PROT3_meth_USR]] | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 3 // CHECK-NEXT: RelC