Index: clang/include/clang/AST/ASTImporter.h =================================================================== --- clang/include/clang/AST/ASTImporter.h +++ clang/include/clang/AST/ASTImporter.h @@ -93,8 +93,6 @@ using NonEquivalentDeclSet = llvm::DenseSet>; using ImportedCXXBaseSpecifierMap = llvm::DenseMap; - using FileIDImportHandlerType = - std::function; enum class ODRHandlingType { Conservative, Liberal }; @@ -220,8 +218,6 @@ }; private: - FileIDImportHandlerType FileIDImportHandler; - std::shared_ptr SharedState = nullptr; /// The path which we go through during the import of a given AST node. @@ -324,14 +320,6 @@ virtual ~ASTImporter(); - /// Set a callback function for FileID import handling. - /// The function is invoked when a FileID is imported from the From context. - /// The imported FileID in the To context and the original FileID in the - /// From context is passed to it. - void setFileIDImportHandler(FileIDImportHandlerType H) { - FileIDImportHandler = H; - } - /// Whether the importer will perform a minimal import, creating /// to-be-completed forward declarations when possible. bool isMinimalImport() const { return Minimal; } Index: clang/include/clang/CrossTU/CrossTranslationUnit.h =================================================================== --- clang/include/clang/CrossTU/CrossTranslationUnit.h +++ clang/include/clang/CrossTU/CrossTranslationUnit.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H #include "clang/AST/ASTImporterSharedState.h" +#include "clang/Analysis/MacroExpansionContext.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" @@ -182,21 +183,18 @@ /// Emit diagnostics for the user for potential configuration errors. void emitCrossTUDiagnostics(const IndexError &IE); - /// Determine the original source location in the original TU for an - /// imported source location. + /// Returns the MacroExpansionContext for the imported TU to which the given + /// source-location corresponds. /// \p ToLoc Source location in the imported-to AST. - /// \return Source location in the imported-from AST and the corresponding - /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit - /// object that is returned here). - /// If any error happens (ToLoc is a non-imported source location) empty is - /// returned. - llvm::Optional> - getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const; + /// \note If any error happens such as \p ToLoc is a non-imported + /// source-location, empty is returned. + /// \note Macro expansion tracking for imported TUs are not implemented yet. + /// It returns empty unconditionally. + llvm::Optional + getMacroExpansionContextForSourceLocation( + const clang::SourceLocation &ToLoc) const; private: - using ImportedFileIDMap = - llvm::DenseMap>; - void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU); ASTImporter &getOrCreateASTImporter(ASTUnit *Unit); template @@ -217,14 +215,6 @@ ASTContext &Context; std::shared_ptr ImporterSharedSt; - /// Map of imported FileID's (in "To" context) to FileID in "From" context - /// and the ASTUnit for the From context. - /// This map is used by getImportedFromSourceLocation to lookup a FileID and - /// its Preprocessor when knowing only the FileID in the 'To' context. The - /// FileID could be imported by any of multiple 'From' ASTImporter objects. - /// we do not want to loop over all ASTImporter's to find the one that - /// imported the FileID. - ImportedFileIDMap ImportedFileIDs; using LoadResultTy = llvm::Expected>; Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -8817,10 +8817,6 @@ assert(ToID.isValid() && "Unexpected invalid fileID was created."); ImportedFileIDs[FromID] = ToID; - - if (FileIDImportHandler) - FileIDImportHandler(ToID, FromID); - return ToID; } Index: clang/lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- clang/lib/CrossTU/CrossTranslationUnit.cpp +++ clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -754,31 +754,15 @@ ASTImporter *NewImporter = new ASTImporter( Context, Context.getSourceManager().getFileManager(), From, From.getSourceManager().getFileManager(), false, ImporterSharedSt); - NewImporter->setFileIDImportHandler([this, Unit](FileID ToID, FileID FromID) { - assert(ImportedFileIDs.find(ToID) == ImportedFileIDs.end() && - "FileID already imported, should not happen."); - ImportedFileIDs[ToID] = std::make_pair(FromID, Unit); - }); ASTUnitImporterMap[From.getTranslationUnitDecl()].reset(NewImporter); return *NewImporter; } -llvm::Optional> -CrossTranslationUnitContext::getImportedFromSourceLocation( +llvm::Optional +CrossTranslationUnitContext::getMacroExpansionContextForSourceLocation( const clang::SourceLocation &ToLoc) const { - const SourceManager &SM = Context.getSourceManager(); - auto DecToLoc = SM.getDecomposedLoc(ToLoc); - - auto I = ImportedFileIDs.find(DecToLoc.first); - if (I == ImportedFileIDs.end()) - return {}; - - FileID FromID = I->second.first; - clang::ASTUnit *Unit = I->second.second; - SourceLocation FromLoc = - Unit->getSourceManager().getComposedLoc(FromID, DecToLoc.second); - - return std::make_pair(FromLoc, Unit); + // FIXME: Implement: Record such a context for every imported ASTUnit; lookup. + return llvm::None; } } // namespace cross_tu Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -157,17 +157,6 @@ } // end of anonymous namespace -namespace { - -struct ExpansionInfo { - std::string MacroName; - std::string Expansion; - ExpansionInfo(std::string N, std::string E) - : MacroName(std::move(N)), Expansion(std::move(E)) {} -}; - -} // end of anonymous namespace - /// Print coverage information to output stream {@code o}. /// May modify the used list of files {@code Fids} by inserting new ones. static void printCoverage(const PathDiagnostic *D, @@ -176,9 +165,9 @@ FIDMap &FM, llvm::raw_fd_ostream &o); -static ExpansionInfo -getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP, - const cross_tu::CrossTranslationUnitContext &CTU); +static Optional getExpandedMacro( + SourceLocation MacroLoc, const cross_tu::CrossTranslationUnitContext &CTU, + const MacroExpansionContext &MacroExpansions, const SourceManager &SM); //===----------------------------------------------------------------------===// // Methods of PlistPrinter. @@ -391,7 +380,17 @@ for (const PathDiagnosticMacroPiece *P : MacroPieces) { const SourceManager &SM = PP.getSourceManager(); - ExpansionInfo EI = getExpandedMacro(P->getLocation().asLocation(), PP, CTU); + + SourceLocation MacroExpansionLoc = + P->getLocation().asLocation().getExpansionLoc(); + + const Optional MacroName = + MacroExpansions.getOriginalText(MacroExpansionLoc); + const Optional ExpansionText = + getExpandedMacro(MacroExpansionLoc, CTU, MacroExpansions, SM); + + if (!MacroName.hasValue() || !ExpansionText.hasValue()) + continue; Indent(o, indent) << "\n"; ++indent; @@ -408,11 +407,11 @@ // Output the macro name. Indent(o, indent) << "name"; - EmitString(o, EI.MacroName) << '\n'; + EmitString(o, MacroName.getValue()) << '\n'; // Output what it expands into. Indent(o, indent) << "expansion"; - EmitString(o, EI.Expansion) << '\n'; + EmitString(o, ExpansionText.getValue()) << '\n'; // Finish up. --indent; @@ -822,571 +821,18 @@ o << "\n\n"; } -//===----------------------------------------------------------------------===// -// Declarations of helper functions and data structures for expanding macros. -//===----------------------------------------------------------------------===// - -namespace { - -using ArgTokensTy = llvm::SmallVector; - -} // end of anonymous namespace - -LLVM_DUMP_METHOD static void dumpArgTokensToStream(llvm::raw_ostream &Out, - const Preprocessor &PP, - const ArgTokensTy &Toks); - -namespace { -/// Maps unexpanded macro parameters to expanded arguments. A macro argument may -/// need to expanded further when it is nested inside another macro. -class MacroParamMap : public std::map { -public: - void expandFromPrevMacro(const MacroParamMap &Super); - - LLVM_DUMP_METHOD void dump(const Preprocessor &PP) const { - dumpToStream(llvm::errs(), PP); - } - - LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out, - const Preprocessor &PP) const; -}; - -struct MacroExpansionInfo { - std::string Name; - const MacroInfo *MI = nullptr; - MacroParamMap ParamMap; - - MacroExpansionInfo(std::string N, const MacroInfo *MI, MacroParamMap M) - : Name(std::move(N)), MI(MI), ParamMap(std::move(M)) {} -}; - -class TokenPrinter { - llvm::raw_ostream &OS; - const Preprocessor &PP; - - Token PrevTok, PrevPrevTok; - TokenConcatenation ConcatInfo; - -public: - TokenPrinter(llvm::raw_ostream &OS, const Preprocessor &PP) - : OS(OS), PP(PP), ConcatInfo(PP) { - PrevTok.setKind(tok::unknown); - PrevPrevTok.setKind(tok::unknown); - } - - void printToken(const Token &Tok); -}; - -/// Wrapper around a Lexer object that can lex tokens one-by-one. Its possible -/// to "inject" a range of tokens into the stream, in which case the next token -/// is retrieved from the next element of the range, until the end of the range -/// is reached. -class TokenStream { -public: - TokenStream(SourceLocation ExpanLoc, const SourceManager &SM, - const LangOptions &LangOpts) - : ExpanLoc(ExpanLoc) { - FileID File; - unsigned Offset; - std::tie(File, Offset) = SM.getDecomposedLoc(ExpanLoc); - llvm::MemoryBufferRef MB = SM.getBufferOrFake(File); - const char *MacroNameTokenPos = MB.getBufferStart() + Offset; - - RawLexer = std::make_unique(SM.getLocForStartOfFile(File), LangOpts, - MB.getBufferStart(), MacroNameTokenPos, - MB.getBufferEnd()); - } - - void next(Token &Result) { - if (CurrTokenIt == TokenRange.end()) { - RawLexer->LexFromRawLexer(Result); - return; - } - Result = *CurrTokenIt; - CurrTokenIt++; - } - - void injectRange(const ArgTokensTy &Range) { - TokenRange = Range; - CurrTokenIt = TokenRange.begin(); - } - - std::unique_ptr RawLexer; - ArgTokensTy TokenRange; - ArgTokensTy::iterator CurrTokenIt = TokenRange.begin(); - SourceLocation ExpanLoc; -}; - -} // end of anonymous namespace - -/// The implementation method of getMacroExpansion: It prints the expansion of -/// a macro to \p Printer, and returns with the name of the macro. -/// -/// Since macros can be nested in one another, this function may call itself -/// recursively. -/// -/// Unfortunately, macro arguments have to expanded manually. To understand why, -/// observe the following example: -/// -/// #define PRINT(x) print(x) -/// #define DO_SOMETHING(str) PRINT(str) -/// -/// DO_SOMETHING("Cute panda cubs."); -/// -/// As we expand the last line, we'll immediately replace PRINT(str) with -/// print(x). The information that both 'str' and 'x' refers to the same string -/// is an information we have to forward, hence the argument \p PrevParamMap. -/// -/// To avoid infinite recursion we maintain the already processed tokens in -/// a set. This is carried as a parameter through the recursive calls. The set -/// is extended with the currently processed token and after processing it, the -/// token is removed. If the token is already in the set, then recursion stops: -/// -/// #define f(y) x -/// #define x f(x) -static std::string getMacroNameAndPrintExpansion( - TokenPrinter &Printer, SourceLocation MacroLoc, const Preprocessor &PP, - const MacroParamMap &PrevParamMap, - llvm::SmallPtrSet &AlreadyProcessedTokens); - -/// Retrieves the name of the macro and what it's parameters expand into -/// at \p ExpanLoc. -/// -/// For example, for the following macro expansion: -/// -/// #define SET_TO_NULL(x) x = 0 -/// #define NOT_SUSPICIOUS(a) \ -/// { \ -/// int b = 0; \ -/// } \ -/// SET_TO_NULL(a) -/// -/// int *ptr = new int(4); -/// NOT_SUSPICIOUS(&ptr); -/// *ptr = 5; -/// -/// When \p ExpanLoc references the last line, the macro name "NOT_SUSPICIOUS" -/// and the MacroArgMap map { (a, &ptr) } will be returned. -/// -/// When \p ExpanLoc references "SET_TO_NULL(a)" within the definition of -/// "NOT_SUSPICOUS", the macro name "SET_TO_NULL" and the MacroArgMap map -/// { (x, a) } will be returned. -static MacroExpansionInfo -getMacroExpansionInfo(const MacroParamMap &PrevParamMap, - SourceLocation ExpanLoc, const Preprocessor &PP); - -/// Retrieves the ')' token that matches '(' \p It points to. -static MacroInfo::tokens_iterator getMatchingRParen( - MacroInfo::tokens_iterator It, - MacroInfo::tokens_iterator End); - -/// Retrieves the macro info for \p II refers to at \p Loc. This is important -/// because macros can be redefined or undefined. -static const MacroInfo *getMacroInfoForLocation(const Preprocessor &PP, - const SourceManager &SM, - const IdentifierInfo *II, - SourceLocation Loc); - //===----------------------------------------------------------------------===// // Definitions of helper functions and methods for expanding macros. //===----------------------------------------------------------------------===// -static ExpansionInfo -getExpandedMacro(SourceLocation MacroLoc, const Preprocessor &PP, - const cross_tu::CrossTranslationUnitContext &CTU) { - - const Preprocessor *PPToUse = &PP; - if (auto LocAndUnit = CTU.getImportedFromSourceLocation(MacroLoc)) { - MacroLoc = LocAndUnit->first; - PPToUse = &LocAndUnit->second->getPreprocessor(); +static Optional +getExpandedMacro(SourceLocation MacroExpansionLoc, + const cross_tu::CrossTranslationUnitContext &CTU, + const MacroExpansionContext &MacroExpansions, + const SourceManager &SM) { + if (auto CTUMacroExpCtx = + CTU.getMacroExpansionContextForSourceLocation(MacroExpansionLoc)) { + return CTUMacroExpCtx->getExpandedText(MacroExpansionLoc); } - - llvm::SmallString<200> ExpansionBuf; - llvm::raw_svector_ostream OS(ExpansionBuf); - TokenPrinter Printer(OS, *PPToUse); - llvm::SmallPtrSet AlreadyProcessedTokens; - - std::string MacroName = getMacroNameAndPrintExpansion( - Printer, MacroLoc, *PPToUse, MacroParamMap{}, AlreadyProcessedTokens); - return {MacroName, std::string(OS.str())}; -} - -static std::string getMacroNameAndPrintExpansion( - TokenPrinter &Printer, SourceLocation MacroLoc, const Preprocessor &PP, - const MacroParamMap &PrevParamMap, - llvm::SmallPtrSet &AlreadyProcessedTokens) { - - const SourceManager &SM = PP.getSourceManager(); - - MacroExpansionInfo MExpInfo = - getMacroExpansionInfo(PrevParamMap, SM.getExpansionLoc(MacroLoc), PP); - IdentifierInfo *MacroNameII = PP.getIdentifierInfo(MExpInfo.Name); - - // TODO: If the macro definition contains another symbol then this function is - // called recursively. In case this symbol is the one being defined, it will - // be an infinite recursion which is stopped by this "if" statement. However, - // in this case we don't get the full expansion text in the Plist file. See - // the test file where "value" is expanded to "garbage_" instead of - // "garbage_value". - if (!AlreadyProcessedTokens.insert(MacroNameII).second) - return MExpInfo.Name; - - if (!MExpInfo.MI) - return MExpInfo.Name; - - // Manually expand its arguments from the previous macro. - MExpInfo.ParamMap.expandFromPrevMacro(PrevParamMap); - - // Iterate over the macro's tokens and stringify them. - for (auto It = MExpInfo.MI->tokens_begin(), E = MExpInfo.MI->tokens_end(); - It != E; ++It) { - Token T = *It; - - // If this token is not an identifier, we only need to print it. - if (T.isNot(tok::identifier)) { - Printer.printToken(T); - continue; - } - - const auto *II = T.getIdentifierInfo(); - assert(II && - "This token is an identifier but has no IdentifierInfo!"); - - // If this token is a macro that should be expanded inside the current - // macro. - if (getMacroInfoForLocation(PP, SM, II, T.getLocation())) { - getMacroNameAndPrintExpansion(Printer, T.getLocation(), PP, - MExpInfo.ParamMap, AlreadyProcessedTokens); - - // If this is a function-like macro, skip its arguments, as - // getExpandedMacro() already printed them. If this is the case, let's - // first jump to the '(' token. - auto N = std::next(It); - if (N != E && N->is(tok::l_paren)) - It = getMatchingRParen(++It, E); - continue; - } - - // If this token is the current macro's argument, we should expand it. - auto ParamToArgIt = MExpInfo.ParamMap.find(II); - if (ParamToArgIt != MExpInfo.ParamMap.end()) { - for (MacroInfo::tokens_iterator ArgIt = ParamToArgIt->second.begin(), - ArgEnd = ParamToArgIt->second.end(); - ArgIt != ArgEnd; ++ArgIt) { - - // These tokens may still be macros, if that is the case, handle it the - // same way we did above. - const auto *ArgII = ArgIt->getIdentifierInfo(); - if (!ArgII) { - Printer.printToken(*ArgIt); - continue; - } - - const auto *MI = PP.getMacroInfo(ArgII); - if (!MI) { - Printer.printToken(*ArgIt); - continue; - } - - getMacroNameAndPrintExpansion(Printer, ArgIt->getLocation(), PP, - MExpInfo.ParamMap, - AlreadyProcessedTokens); - // Peek the next token if it is a tok::l_paren. This way we can decide - // if this is the application or just a reference to a function maxro - // symbol: - // - // #define apply(f) ... - // #define func(x) ... - // apply(func) - // apply(func(42)) - auto N = std::next(ArgIt); - if (N != ArgEnd && N->is(tok::l_paren)) - ArgIt = getMatchingRParen(++ArgIt, ArgEnd); - } - continue; - } - - // If control reached here, then this token isn't a macro identifier, nor an - // unexpanded macro argument that we need to handle, print it. - Printer.printToken(T); - } - - AlreadyProcessedTokens.erase(MacroNameII); - - return MExpInfo.Name; -} - -static MacroExpansionInfo -getMacroExpansionInfo(const MacroParamMap &PrevParamMap, - SourceLocation ExpanLoc, const Preprocessor &PP) { - - const SourceManager &SM = PP.getSourceManager(); - const LangOptions &LangOpts = PP.getLangOpts(); - - // First, we create a Lexer to lex *at the expansion location* the tokens - // referring to the macro's name and its arguments. - TokenStream TStream(ExpanLoc, SM, LangOpts); - - // Acquire the macro's name. - Token TheTok; - TStream.next(TheTok); - - std::string MacroName = PP.getSpelling(TheTok); - - const auto *II = PP.getIdentifierInfo(MacroName); - assert(II && "Failed to acquire the IdentifierInfo for the macro!"); - - const MacroInfo *MI = getMacroInfoForLocation(PP, SM, II, ExpanLoc); - // assert(MI && "The macro must've been defined at it's expansion location!"); - // - // We should always be able to obtain the MacroInfo in a given TU, but if - // we're running the analyzer with CTU, the Preprocessor won't contain the - // directive history (or anything for that matter) from another TU. - // TODO: assert when we're not running with CTU. - if (!MI) - return { MacroName, MI, {} }; - - // Acquire the macro's arguments at the expansion point. - // - // The rough idea here is to lex from the first left parentheses to the last - // right parentheses, and map the macro's parameter to what they will be - // expanded to. A macro argument may contain several token (like '3 + 4'), so - // we'll lex until we find a tok::comma or tok::r_paren, at which point we - // start lexing the next argument or finish. - ArrayRef MacroParams = MI->params(); - if (MacroParams.empty()) - return { MacroName, MI, {} }; - - TStream.next(TheTok); - // When this is a token which expands to another macro function then its - // parentheses are not at its expansion locaiton. For example: - // - // #define foo(x) int bar() { return x; } - // #define apply_zero(f) f(0) - // apply_zero(foo) - // ^ - // This is not a tok::l_paren, but foo is a function. - if (TheTok.isNot(tok::l_paren)) - return { MacroName, MI, {} }; - - MacroParamMap ParamMap; - - // When the argument is a function call, like - // CALL_FN(someFunctionName(param1, param2)) - // we will find tok::l_paren, tok::r_paren, and tok::comma that do not divide - // actual macro arguments, or do not represent the macro argument's closing - // parentheses, so we'll count how many parentheses aren't closed yet. - // If ParanthesesDepth - // * = 0, then there are no more arguments to lex. - // * = 1, then if we find a tok::comma, we can start lexing the next arg. - // * > 1, then tok::comma is a part of the current arg. - int ParenthesesDepth = 1; - - // If we encounter the variadic arg, we will lex until the closing - // tok::r_paren, even if we lex a tok::comma and ParanthesesDepth == 1. - const IdentifierInfo *VariadicParamII = PP.getIdentifierInfo("__VA_ARGS__"); - if (MI->isGNUVarargs()) { - // If macro uses GNU-style variadic args, the param name is user-supplied, - // an not "__VA_ARGS__". E.g.: - // #define FOO(a, b, myvargs...) - // In this case, just use the last parameter: - VariadicParamII = *(MacroParams.rbegin()); - } - - for (const IdentifierInfo *CurrParamII : MacroParams) { - MacroParamMap::mapped_type ArgTokens; - - // One could also simply not supply a single argument to __VA_ARGS__ -- this - // results in a preprocessor warning, but is not an error: - // #define VARIADIC(ptr, ...) \ - // someVariadicTemplateFunction(__VA_ARGS__) - // - // int *ptr; - // VARIADIC(ptr); // Note that there are no commas, this isn't just an - // // empty parameter -- there are no parameters for '...'. - // In any other case, ParenthesesDepth mustn't be 0 here. - if (ParenthesesDepth != 0) { - - // Lex the first token of the next macro parameter. - TStream.next(TheTok); - - while (CurrParamII == VariadicParamII || ParenthesesDepth != 1 || - !TheTok.is(tok::comma)) { - assert(TheTok.isNot(tok::eof) && - "EOF encountered while looking for expanded macro args!"); - - if (TheTok.is(tok::l_paren)) - ++ParenthesesDepth; - - if (TheTok.is(tok::r_paren)) - --ParenthesesDepth; - - if (ParenthesesDepth == 0) - break; - - if (TheTok.is(tok::raw_identifier)) { - PP.LookUpIdentifierInfo(TheTok); - // This token is a variadic parameter: - // - // #define PARAMS_RESOLVE_TO_VA_ARGS(i, fmt) foo(i, fmt); \ - // i = 0; - // #define DISPATCH(...) \ - // PARAMS_RESOLVE_TO_VA_ARGS(__VA_ARGS__); - // // ^~~~~~~~~~~ Variadic parameter here - // - // void multipleParamsResolveToVA_ARGS(void) { - // int x = 1; - // DISPATCH(x, "LF1M healer"); // Multiple arguments are mapped to - // // a single __VA_ARGS__ parameter. - // (void)(10 / x); - // } - // - // We will stumble across this while trying to expand - // PARAMS_RESOLVE_TO_VA_ARGS. By this point, we already noted during - // the processing of DISPATCH what __VA_ARGS__ maps to, so we'll - // retrieve the next series of tokens from that. - if (TheTok.getIdentifierInfo() == VariadicParamII) { - TStream.injectRange(PrevParamMap.at(VariadicParamII)); - TStream.next(TheTok); - continue; - } - } - - ArgTokens.push_back(TheTok); - TStream.next(TheTok); - } - } else { - assert(CurrParamII == VariadicParamII && - "No more macro arguments are found, but the current parameter " - "isn't the variadic arg!"); - } - - ParamMap.emplace(CurrParamII, std::move(ArgTokens)); - } - - assert(TheTok.is(tok::r_paren) && - "Expanded macro argument acquisition failed! After the end of the loop" - " this token should be ')'!"); - - return {MacroName, MI, ParamMap}; -} - -static MacroInfo::tokens_iterator getMatchingRParen( - MacroInfo::tokens_iterator It, - MacroInfo::tokens_iterator End) { - - assert(It->is(tok::l_paren) && "This token should be '('!"); - - // Skip until we find the closing ')'. - int ParenthesesDepth = 1; - while (ParenthesesDepth != 0) { - ++It; - - assert(It->isNot(tok::eof) && - "Encountered EOF while attempting to skip macro arguments!"); - assert(It != End && - "End of the macro definition reached before finding ')'!"); - - if (It->is(tok::l_paren)) - ++ParenthesesDepth; - - if (It->is(tok::r_paren)) - --ParenthesesDepth; - } - return It; -} - -static const MacroInfo *getMacroInfoForLocation(const Preprocessor &PP, - const SourceManager &SM, - const IdentifierInfo *II, - SourceLocation Loc) { - - const MacroDirective *MD = PP.getLocalMacroDirectiveHistory(II); - if (!MD) - return nullptr; - - return MD->findDirectiveAtLoc(Loc, SM).getMacroInfo(); -} - -void MacroParamMap::expandFromPrevMacro(const MacroParamMap &Super) { - - for (value_type &Pair : *this) { - ArgTokensTy &CurrArgTokens = Pair.second; - - // For each token in the expanded macro argument. - auto It = CurrArgTokens.begin(); - while (It != CurrArgTokens.end()) { - if (It->isNot(tok::identifier)) { - ++It; - continue; - } - - const auto *II = It->getIdentifierInfo(); - assert(II); - - // Is this an argument that "Super" expands further? - if (!Super.count(II)) { - ++It; - continue; - } - - const ArgTokensTy &SuperArgTokens = Super.at(II); - - It = CurrArgTokens.insert(It, SuperArgTokens.begin(), - SuperArgTokens.end()); - std::advance(It, SuperArgTokens.size()); - It = CurrArgTokens.erase(It); - } - } -} - -void MacroParamMap::dumpToStream(llvm::raw_ostream &Out, - const Preprocessor &PP) const { - for (const std::pair Pair : *this) { - Out << Pair.first->getName() << " -> "; - dumpArgTokensToStream(Out, PP, Pair.second); - Out << '\n'; - } -} - -static void dumpArgTokensToStream(llvm::raw_ostream &Out, - const Preprocessor &PP, - const ArgTokensTy &Toks) { - TokenPrinter Printer(Out, PP); - for (Token Tok : Toks) - Printer.printToken(Tok); -} - -void TokenPrinter::printToken(const Token &Tok) { - // TODO: Handle GNU extensions where hash and hashhash occurs right before - // __VA_ARGS__. - // cppreference.com: "some compilers offer an extension that allows ## to - // appear after a comma and before __VA_ARGS__, in which case the ## does - // nothing when the variable arguments are present, but removes the comma when - // the variable arguments are not present: this makes it possible to define - // macros such as fprintf (stderr, format, ##__VA_ARGS__)" - // FIXME: Handle named variadic macro parameters (also a GNU extension). - - // If this is the first token to be printed, don't print space. - if (PrevTok.isNot(tok::unknown)) { - // If the tokens were already space separated, or if they must be to avoid - // them being implicitly pasted, add a space between them. - if(Tok.hasLeadingSpace() || ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, - Tok)) { - // AvoidConcat doesn't check for ##, don't print a space around it. - if (PrevTok.isNot(tok::hashhash) && Tok.isNot(tok::hashhash)) { - OS << ' '; - } - } - } - - if (!Tok.isOneOf(tok::hash, tok::hashhash)) { - if (PrevTok.is(tok::hash)) - OS << '\"' << PP.getSpelling(Tok) << '\"'; - else - OS << PP.getSpelling(Tok); - } - - PrevPrevTok = PrevTok; - PrevTok = Tok; + return MacroExpansions.getExpandedText(MacroExpansionLoc); } Index: clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist =================================================================== --- clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist +++ /dev/null @@ -1,6931 +0,0 @@ - - - - - clang_version - diagnostics - - - path - - - kindcontrol - edges - - - start - - - line23 - col3 - file0 - - - line23 - col5 - file0 - - - end - - - line24 - col3 - file0 - - - line24 - col21 - file0 - - - - - - - kindevent - location - - line24 - col3 - file0 - - ranges - - - - line24 - col3 - file0 - - - line24 - col21 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line25 - col3 - file0 - - - line25 - col3 - file0 - - - end - - - line25 - col8 - file0 - - - line25 - col8 - file0 - - - - - - - kindevent - location - - line25 - col8 - file0 - - ranges - - - - line25 - col4 - file0 - - - line25 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line24 - col3 - file0 - - nameSET_PTR_VAR_TO_NULL - expansionptr = 0 - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextf8fbc46cc5afbb056d92bd3d3d702781 - issue_context_kindfunction - issue_contextnonFunctionLikeMacroTest - issue_hash_function_offset3 - location - - line25 - col8 - file0 - - ExecutedLines - - 0 - - 22 - 23 - 24 - 25 - - - - - path - - - kindcontrol - edges - - - start - - - line36 - col3 - file0 - - - line36 - col5 - file0 - - - end - - - line37 - col3 - file0 - - - line37 - col39 - file0 - - - - - - - kindevent - location - - line37 - col3 - file0 - - ranges - - - - line37 - col3 - file0 - - - line37 - col39 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line38 - col3 - file0 - - - line38 - col3 - file0 - - - end - - - line38 - col8 - file0 - - - line38 - col8 - file0 - - - - - - - kindevent - location - - line38 - col8 - file0 - - ranges - - - - line38 - col4 - file0 - - - line38 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line37 - col3 - file0 - - nameSET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO - expansionptr =0 - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextd5eba61193b41c27fc7b2705cbd607ba - issue_context_kindfunction - issue_contextnonFunctionLikeNestedMacroTest - issue_hash_function_offset3 - location - - line38 - col8 - file0 - - ExecutedLines - - 0 - - 35 - 36 - 37 - 38 - - - - - path - - - kindcontrol - edges - - - start - - - line56 - col3 - file0 - - - line56 - col5 - file0 - - - end - - - line57 - col3 - file0 - - - line57 - col9 - file0 - - - - - - - kindevent - location - - line57 - col3 - file0 - - ranges - - - - line57 - col3 - file0 - - - line57 - col15 - file0 - - - - depth0 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth1 - extended_message - Entered call from 'functionLikeMacroTest' - message - Entered call from 'functionLikeMacroTest' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth1 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindevent - location - - line57 - col3 - file0 - - ranges - - - - line57 - col3 - file0 - - - line57 - col15 - file0 - - - - depth0 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindcontrol - edges - - - start - - - line58 - col3 - file0 - - - line58 - col3 - file0 - - - end - - - line58 - col8 - file0 - - - line58 - col8 - file0 - - - - - - - kindevent - location - - line58 - col8 - file0 - - ranges - - - - line58 - col4 - file0 - - - line58 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line57 - col3 - file0 - - nameTO_NULL - expansionsetToNull(&ptr) - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context370a457744311752aac789447b4ef16c - issue_context_kindfunction - issue_contextfunctionLikeMacroTest - issue_hash_function_offset3 - location - - line58 - col8 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 55 - 56 - 57 - 58 - - - - - path - - - kindcontrol - edges - - - start - - - line76 - col3 - file0 - - - line76 - col5 - file0 - - - end - - - line77 - col3 - file0 - - - line77 - col9 - file0 - - - - - - - kindevent - location - - line77 - col3 - file0 - - ranges - - - - line77 - col3 - file0 - - - line77 - col13 - file0 - - - - depth0 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth1 - extended_message - Entered call from 'functionLikeNestedMacroTest' - message - Entered call from 'functionLikeNestedMacroTest' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth1 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindevent - location - - line77 - col3 - file0 - - ranges - - - - line77 - col3 - file0 - - - line77 - col13 - file0 - - - - depth0 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindevent - location - - line78 - col12 - file0 - - ranges - - - - line78 - col3 - file0 - - - line78 - col10 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line77 - col3 - file0 - - nameTO_NULL - expansionsetToNull(&a) - - - location - - line78 - col3 - file0 - - nameDEREF - expansion{ int b; b = 5; } print(a); *a - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context873802674657bba4565f64c7bbf0ded9 - issue_context_kindfunction - issue_contextfunctionLikeNestedMacroTest - issue_hash_function_offset3 - location - - line78 - col12 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 75 - 76 - 77 - 78 - - - - - path - - - kindcontrol - edges - - - start - - - line95 - col3 - file0 - - - line95 - col5 - file0 - - - end - - - line96 - col3 - file0 - - - line96 - col28 - file0 - - - - - - - kindevent - location - - line96 - col3 - file0 - - ranges - - - - line96 - col3 - file0 - - - line96 - col33 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line97 - col3 - file0 - - - line97 - col3 - file0 - - - end - - - line97 - col8 - file0 - - - line97 - col8 - file0 - - - - - - - kindevent - location - - line97 - col8 - file0 - - ranges - - - - line97 - col4 - file0 - - - line97 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line96 - col3 - file0 - - nameWILL_UNDEF_SET_NULL_TO_PTR - expansionptr = nullptr; - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context79ce7ac344a15505929edba2fdf178b6 - issue_context_kindfunction - issue_contextundefinedMacroByTheEndOfParsingTest - issue_hash_function_offset3 - location - - line97 - col8 - file0 - - ExecutedLines - - 0 - - 94 - 95 - 96 - 97 - - - - - path - - - kindcontrol - edges - - - start - - - line112 - col3 - file0 - - - line112 - col5 - file0 - - - end - - - line113 - col3 - file0 - - - line113 - col42 - file0 - - - - - - - kindevent - location - - line113 - col3 - file0 - - ranges - - - - line113 - col3 - file0 - - - line113 - col47 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line114 - col3 - file0 - - - line114 - col3 - file0 - - - end - - - line114 - col8 - file0 - - - line114 - col8 - file0 - - - - - - - kindevent - location - - line114 - col8 - file0 - - ranges - - - - line114 - col4 - file0 - - - line114 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line113 - col3 - file0 - - nameWILL_REDIFINE_MULTIPLE_TIMES_SET_TO_NULL - expansionptr = nullptr; - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextcbbecfb64198aebb884f3729dff84896 - issue_context_kindfunction - issue_contextmacroRedefinedMultipleTimesTest - issue_hash_function_offset3 - location - - line114 - col8 - file0 - - ExecutedLines - - 0 - - 111 - 112 - 113 - 114 - - - - - path - - - kindcontrol - edges - - - start - - - line132 - col3 - file0 - - - line132 - col5 - file0 - - - end - - - line133 - col3 - file0 - - - line133 - col39 - file0 - - - - - - - kindevent - location - - line133 - col3 - file0 - - ranges - - - - line133 - col3 - file0 - - - line133 - col44 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line134 - col3 - file0 - - - line134 - col3 - file0 - - - end - - - line134 - col8 - file0 - - - line134 - col8 - file0 - - - - - - - kindevent - location - - line134 - col8 - file0 - - ranges - - - - line134 - col4 - file0 - - - line134 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line133 - col3 - file0 - - namePASS_PTR_TO_MACRO_THAT_WILL_BE_UNDEFD - expansionptr = nullptr; - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context01684c77381713fd6c7be31ebc9b647a - issue_context_kindfunction - issue_contextundefinedMacroInsideAnotherMacroTest - issue_hash_function_offset3 - location - - line134 - col8 - file0 - - ExecutedLines - - 0 - - 131 - 132 - 133 - 134 - - - - - path - - - kindcontrol - edges - - - start - - - line159 - col3 - file0 - - - line159 - col5 - file0 - - - end - - - line160 - col3 - file0 - - - line160 - col19 - file0 - - - - - - - kindevent - location - - line160 - col3 - file0 - - ranges - - - - line160 - col3 - file0 - - - line160 - col52 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindcontrol - edges - - - start - - - line161 - col3 - file0 - - - line161 - col3 - file0 - - - end - - - line161 - col6 - file0 - - - line161 - col6 - file0 - - - - - - - kindevent - location - - line161 - col6 - file0 - - ranges - - - - line161 - col4 - file0 - - - line161 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line160 - col3 - file0 - - nameTO_NULL_AND_PRINT - expansiona = 0; print( "Will this , cause a crash?") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context7a7344244350405a514682fe228e304e - issue_context_kindfunction - issue_contextmacroArgContainsCommaInStringTest - issue_hash_function_offset3 - location - - line161 - col6 - file0 - - ExecutedLines - - 0 - - 158 - 159 - 160 - 161 - - - - - path - - - kindcontrol - edges - - - start - - - line168 - col3 - file0 - - - line168 - col5 - file0 - - - end - - - line169 - col3 - file0 - - - line169 - col19 - file0 - - - - - - - kindevent - location - - line169 - col3 - file0 - - ranges - - - - line169 - col3 - file0 - - - line169 - col52 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindcontrol - edges - - - start - - - line170 - col3 - file0 - - - line170 - col3 - file0 - - - end - - - line170 - col6 - file0 - - - line170 - col6 - file0 - - - - - - - kindevent - location - - line170 - col6 - file0 - - ranges - - - - line170 - col4 - file0 - - - line170 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line169 - col3 - file0 - - nameTO_NULL_AND_PRINT - expansiona = 0; print( "Will this ( cause a crash?") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context1d6d14e3f566cec02bd1f3542e3c8044 - issue_context_kindfunction - issue_contextmacroArgContainsLParenInStringTest - issue_hash_function_offset3 - location - - line170 - col6 - file0 - - ExecutedLines - - 0 - - 167 - 168 - 169 - 170 - - - - - path - - - kindcontrol - edges - - - start - - - line177 - col3 - file0 - - - line177 - col5 - file0 - - - end - - - line178 - col3 - file0 - - - line178 - col19 - file0 - - - - - - - kindevent - location - - line178 - col3 - file0 - - ranges - - - - line178 - col3 - file0 - - - line178 - col52 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindcontrol - edges - - - start - - - line179 - col3 - file0 - - - line179 - col3 - file0 - - - end - - - line179 - col6 - file0 - - - line179 - col6 - file0 - - - - - - - kindevent - location - - line179 - col6 - file0 - - ranges - - - - line179 - col4 - file0 - - - line179 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line178 - col3 - file0 - - nameTO_NULL_AND_PRINT - expansiona = 0; print( "Will this ) cause a crash?") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context7354d762d71f0d0a3ffc9d6d827fe580 - issue_context_kindfunction - issue_contextmacroArgContainsRParenInStringTest - issue_hash_function_offset3 - location - - line179 - col6 - file0 - - ExecutedLines - - 0 - - 176 - 177 - 178 - 179 - - - - - path - - - kindcontrol - edges - - - start - - - line191 - col3 - file0 - - - line191 - col5 - file0 - - - end - - - line192 - col3 - file0 - - - line192 - col15 - file0 - - - - - - - kindevent - location - - line192 - col3 - file0 - - ranges - - - - line192 - col3 - file0 - - - line192 - col30 - file0 - - - - depth0 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth1 - extended_message - Entered call from 'macroArgContainsLParenRParenTest' - message - Entered call from 'macroArgContainsLParenRParenTest' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth1 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindevent - location - - line192 - col3 - file0 - - ranges - - - - line192 - col3 - file0 - - - line192 - col30 - file0 - - - - depth0 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindcontrol - edges - - - start - - - line193 - col3 - file0 - - - line193 - col3 - file0 - - - end - - - line193 - col6 - file0 - - - line193 - col6 - file0 - - - - - - - kindevent - location - - line193 - col6 - file0 - - ranges - - - - line193 - col4 - file0 - - - line193 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line192 - col3 - file0 - - nameCALL_FUNCTION - expansionsetToNull(&a) - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextf00b6f77288a374e864a58609e9a42ea - issue_context_kindfunction - issue_contextmacroArgContainsLParenRParenTest - issue_hash_function_offset3 - location - - line193 - col6 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 190 - 191 - 192 - 193 - - - - - path - - - kindcontrol - edges - - - start - - - line205 - col3 - file0 - - - line205 - col5 - file0 - - - end - - - line206 - col3 - file0 - - - line206 - col15 - file0 - - - - - - - kindevent - location - - line206 - col3 - file0 - - ranges - - - - line206 - col3 - file0 - - - line206 - col48 - file0 - - - - depth0 - extended_message - Calling 'setToNullAndPrint' - message - Calling 'setToNullAndPrint' - - - kindevent - location - - line199 - col1 - file0 - - depth1 - extended_message - Entered call from 'macroArgContainsCommaLParenRParenTest' - message - Entered call from 'macroArgContainsCommaLParenRParenTest' - - - kindcontrol - edges - - - start - - - line199 - col1 - file0 - - - line199 - col4 - file0 - - - end - - - line200 - col3 - file0 - - - line200 - col11 - file0 - - - - - - - kindevent - location - - line200 - col3 - file0 - - ranges - - - - line200 - col3 - file0 - - - line200 - col17 - file0 - - - - depth1 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth2 - extended_message - Entered call from 'setToNullAndPrint' - message - Entered call from 'setToNullAndPrint' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth2 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindevent - location - - line200 - col3 - file0 - - ranges - - - - line200 - col3 - file0 - - - line200 - col17 - file0 - - - - depth1 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindcontrol - edges - - - start - - - line200 - col3 - file0 - - - line200 - col11 - file0 - - - end - - - line201 - col3 - file0 - - - line201 - col7 - file0 - - - - - - - kindevent - location - - line206 - col3 - file0 - - ranges - - - - line206 - col3 - file0 - - - line206 - col48 - file0 - - - - depth0 - extended_message - Returning from 'setToNullAndPrint' - message - Returning from 'setToNullAndPrint' - - - kindcontrol - edges - - - start - - - line207 - col3 - file0 - - - line207 - col3 - file0 - - - end - - - line207 - col6 - file0 - - - line207 - col6 - file0 - - - - - - - kindevent - location - - line207 - col6 - file0 - - ranges - - - - line207 - col4 - file0 - - - line207 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line206 - col3 - file0 - - nameCALL_FUNCTION - expansionsetToNullAndPrint(&a, "Hello!") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextc5805abeb71bb4edb41b49ab317439b9 - issue_context_kindfunction - issue_contextmacroArgContainsCommaLParenRParenTest - issue_hash_function_offset3 - location - - line207 - col6 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 199 - 200 - 201 - 204 - 205 - 206 - 207 - - - - - path - - - kindcontrol - edges - - - start - - - line217 - col3 - file0 - - - line217 - col5 - file0 - - - end - - - line218 - col3 - file0 - - - line218 - col31 - file0 - - - - - - - kindevent - location - - line218 - col3 - file0 - - ranges - - - - line218 - col3 - file0 - - - line218 - col64 - file0 - - - - depth0 - extended_message - Calling 'setToNullAndPrint' - message - Calling 'setToNullAndPrint' - - - kindevent - location - - line199 - col1 - file0 - - depth1 - extended_message - Entered call from 'macroArgContainsCommaLParenRParenTest2' - message - Entered call from 'macroArgContainsCommaLParenRParenTest2' - - - kindcontrol - edges - - - start - - - line199 - col1 - file0 - - - line199 - col4 - file0 - - - end - - - line200 - col3 - file0 - - - line200 - col11 - file0 - - - - - - - kindevent - location - - line200 - col3 - file0 - - ranges - - - - line200 - col3 - file0 - - - line200 - col17 - file0 - - - - depth1 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth2 - extended_message - Entered call from 'setToNullAndPrint' - message - Entered call from 'setToNullAndPrint' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth2 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindevent - location - - line200 - col3 - file0 - - ranges - - - - line200 - col3 - file0 - - - line200 - col17 - file0 - - - - depth1 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindcontrol - edges - - - start - - - line200 - col3 - file0 - - - line200 - col11 - file0 - - - end - - - line201 - col3 - file0 - - - line201 - col7 - file0 - - - - - - - kindevent - location - - line218 - col3 - file0 - - ranges - - - - line218 - col3 - file0 - - - line218 - col64 - file0 - - - - depth0 - extended_message - Returning from 'setToNullAndPrint' - message - Returning from 'setToNullAndPrint' - - - kindcontrol - edges - - - start - - - line219 - col3 - file0 - - - line219 - col3 - file0 - - - end - - - line219 - col6 - file0 - - - line219 - col6 - file0 - - - - - - - kindevent - location - - line219 - col6 - file0 - - ranges - - - - line219 - col4 - file0 - - - line219 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line218 - col3 - file0 - - nameCALL_FUNCTION_WITH_TWO_PARAMS - expansionsetToNullAndPrint( &a, "Hello!") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context4014a22ef054933e6ce9be43623ea85e - issue_context_kindfunction - issue_contextmacroArgContainsCommaLParenRParenTest2 - issue_hash_function_offset3 - location - - line219 - col6 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 199 - 200 - 201 - 216 - 217 - 218 - 219 - - - - - path - - - kindcontrol - edges - - - start - - - line229 - col3 - file0 - - - line229 - col5 - file0 - - - end - - - line233 - col3 - file0 - - - line233 - col13 - file0 - - - - - - - kindevent - location - - line233 - col3 - file0 - - ranges - - - - line233 - col3 - file0 - - - line233 - col58 - file0 - - - - depth0 - extended_message - Calling 'operator()' - message - Calling 'operator()' - - - kindevent - location - - line233 - col3 - file0 - - depth1 - extended_message - Entered call from 'commaInBracketsTest' - message - Entered call from 'commaInBracketsTest' - - - kindevent - location - - line233 - col3 - file0 - - ranges - - - - line233 - col3 - file0 - - - line233 - col58 - file0 - - - - depth1 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth2 - extended_message - Entered call from 'operator()' - message - Entered call from 'operator()' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth2 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindevent - location - - line233 - col3 - file0 - - ranges - - - - line233 - col3 - file0 - - - line233 - col58 - file0 - - - - depth1 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindevent - location - - line233 - col3 - file0 - - ranges - - - - line233 - col3 - file0 - - - line233 - col58 - file0 - - - - depth0 - extended_message - Returning from 'operator()' - message - Returning from 'operator()' - - - kindcontrol - edges - - - start - - - line234 - col3 - file0 - - - line234 - col3 - file0 - - - end - - - line234 - col8 - file0 - - - line234 - col8 - file0 - - - - - - - kindevent - location - - line234 - col8 - file0 - - ranges - - - - line234 - col4 - file0 - - - line234 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line233 - col3 - file0 - - nameCALL_LAMBDA - expansion([&ptr, str] () mutable { setToNull(&ptr); })() - - - location - - line233 - col3 - file0 - - nameCALL_LAMBDA - expansion([&ptr, str] () mutable { setToNull(&ptr); })() - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contexta8918c38ddfa6a991701e7d19c9cd6bb - issue_context_kindfunction - issue_contextcommaInBracketsTest - issue_hash_function_offset6 - location - - line234 - col8 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 228 - 229 - 230 - 233 - 234 - - - - - path - - - kindevent - location - - line244 - col3 - file0 - - ranges - - - - line244 - col3 - file0 - - - line252 - col4 - file0 - - - - depth0 - extended_message - 'ptr' initialized to a null pointer value - message - 'ptr' initialized to a null pointer value - - - kindevent - location - - line244 - col3 - file0 - - ranges - - - - line244 - col3 - file0 - - - line252 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line244 - col3 - file0 - - namePASTE_CODE - expansion{ int *ptr = nullptr; *ptr = 5; } - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context63042e03ae0d2f3832b141a63b1d4d49 - issue_context_kindfunction - issue_contextcommaInBracesTest - issue_hash_function_offset1 - location - - line244 - col3 - file0 - - ExecutedLines - - 0 - - 243 - 244 - - - - - path - - - kindcontrol - edges - - - start - - - line266 - col3 - file0 - - - line266 - col5 - file0 - - - end - - - line268 - col3 - file0 - - - line268 - col25 - file0 - - - - - - - kindevent - location - - line268 - col3 - file0 - - ranges - - - - line268 - col3 - file0 - - - line268 - col31 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line269 - col3 - file0 - - - line269 - col3 - file0 - - - end - - - line269 - col8 - file0 - - - line269 - col8 - file0 - - - - - - - kindevent - location - - line269 - col8 - file0 - - ranges - - - - line269 - col4 - file0 - - - line269 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line268 - col3 - file0 - - namePOTENTIALLY_EMPTY_PARAM - expansion;ptr = nullptr - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextcd980e278fbcd8f77bbeac79285084e2 - issue_context_kindfunction - issue_contextemptyParamTest - issue_hash_function_offset4 - location - - line269 - col8 - file0 - - ExecutedLines - - 0 - - 265 - 266 - 268 - 269 - - - - - path - - - kindcontrol - edges - - - start - - - line280 - col3 - file0 - - - line280 - col5 - file0 - - - end - - - line282 - col3 - file0 - - - line282 - col20 - file0 - - - - - - - kindevent - location - - line282 - col3 - file0 - - ranges - - - - line282 - col3 - file0 - - - line282 - col27 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line283 - col3 - file0 - - - line283 - col3 - file0 - - - end - - - line283 - col8 - file0 - - - line283 - col8 - file0 - - - - - - - kindevent - location - - line283 - col8 - file0 - - ranges - - - - line283 - col4 - file0 - - - line283 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line282 - col3 - file0 - - nameNESTED_EMPTY_PARAM - expansion; ptr = nullptr; - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextf6a5f6c93b6e3734842ddabd3d5a7341 - issue_context_kindfunction - issue_contextnestedEmptyParamTest - issue_hash_function_offset4 - location - - line283 - col8 - file0 - - ExecutedLines - - 0 - - 279 - 280 - 282 - 283 - - - - - path - - - kindcontrol - edges - - - start - - - line293 - col3 - file0 - - - line293 - col5 - file0 - - - end - - - line294 - col3 - file0 - - - line294 - col44 - file0 - - - - - - - kindevent - location - - line294 - col3 - file0 - - ranges - - - - line294 - col3 - file0 - - - line294 - col61 - file0 - - - - depth0 - extended_message - Calling 'setToNull' - message - Calling 'setToNull' - - - kindevent - location - - line48 - col1 - file0 - - depth1 - extended_message - Entered call from 'lParenRParenInNestedMacro' - message - Entered call from 'lParenRParenInNestedMacro' - - - kindcontrol - edges - - - start - - - line48 - col1 - file0 - - - line48 - col4 - file0 - - - end - - - line49 - col3 - file0 - - - line49 - col3 - file0 - - - - - - - kindevent - location - - line49 - col3 - file0 - - ranges - - - - line49 - col3 - file0 - - - line49 - col17 - file0 - - - - depth1 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindevent - location - - line294 - col3 - file0 - - ranges - - - - line294 - col3 - file0 - - - line294 - col61 - file0 - - - - depth0 - extended_message - Returning from 'setToNull' - message - Returning from 'setToNull' - - - kindcontrol - edges - - - start - - - line295 - col3 - file0 - - - line295 - col3 - file0 - - - end - - - line295 - col8 - file0 - - - line295 - col8 - file0 - - - - - - - kindevent - location - - line295 - col8 - file0 - - ranges - - - - line295 - col4 - file0 - - - line295 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line294 - col3 - file0 - - nameCALL_FUNCTION_WITH_ONE_PARAM_THROUGH_MACRO - expansionsetToNull( &ptr) - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextff00c8344e685317303e814970082d5f - issue_context_kindfunction - issue_contextlParenRParenInNestedMacro - issue_hash_function_offset3 - location - - line295 - col8 - file0 - - ExecutedLines - - 0 - - 48 - 49 - 292 - 293 - 294 - 295 - - - - - path - - - kindcontrol - edges - - - start - - - line313 - col3 - file0 - - - line313 - col5 - file0 - - - end - - - line314 - col3 - file0 - - - line314 - col22 - file0 - - - - - - - kindevent - location - - line314 - col3 - file0 - - ranges - - - - line314 - col3 - file0 - - - line314 - col42 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line315 - col3 - file0 - - - line315 - col3 - file0 - - - end - - - line315 - col8 - file0 - - - line315 - col8 - file0 - - - - - - - kindevent - location - - line315 - col8 - file0 - - ranges - - - - line315 - col4 - file0 - - - line315 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line314 - col3 - file0 - - nameVARIADIC_SET_TO_NULL - expansionptr = nullptr; variadicFunc( 1, 5, "haha!") - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context1b0880549df23e9ce0edb60955ad5ac1 - issue_context_kindfunction - issue_contextvariadicMacroArgumentTest - issue_hash_function_offset3 - location - - line315 - col8 - file0 - - ExecutedLines - - 0 - - 312 - 313 - 314 - 315 - - - - - path - - - kindcontrol - edges - - - start - - - line322 - col3 - file0 - - - line322 - col5 - file0 - - - end - - - line325 - col3 - file0 - - - line325 - col22 - file0 - - - - - - - kindevent - location - - line325 - col3 - file0 - - ranges - - - - line325 - col3 - file0 - - - line325 - col27 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line326 - col3 - file0 - - - line326 - col3 - file0 - - - end - - - line326 - col8 - file0 - - - line326 - col8 - file0 - - - - - - - kindevent - location - - line326 - col8 - file0 - - ranges - - - - line326 - col4 - file0 - - - line326 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line325 - col3 - file0 - - nameVARIADIC_SET_TO_NULL - expansionptr = nullptr; variadicFunc() - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context6aa30fd6a1e997027333f16c2064d973 - issue_context_kindfunction - issue_contextvariadicMacroArgumentWithoutAnyArgumentTest - issue_hash_function_offset5 - location - - line326 - col8 - file0 - - ExecutedLines - - 0 - - 321 - 322 - 325 - 326 - - - - - path - - - kindcontrol - edges - - - start - - - line341 - col3 - file0 - - - line341 - col5 - file0 - - - end - - - line342 - col3 - file0 - - - line342 - col30 - file0 - - - - - - - kindevent - location - - line342 - col3 - file0 - - ranges - - - - line342 - col3 - file0 - - - line342 - col45 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line343 - col3 - file0 - - - line343 - col3 - file0 - - - end - - - line343 - col8 - file0 - - - line343 - col8 - file0 - - - - - - - kindevent - location - - line343 - col8 - file0 - - ranges - - - - line343 - col4 - file0 - - - line343 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line342 - col3 - file0 - - nameDECLARE_FUNC_AND_SET_TO_NULL - expansionvoid generated_whatever(); ptr = nullptr; - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context453ed8096f5394e74e16f965886e5623 - issue_context_kindfunction - issue_contexthashHashOperatorTest - issue_hash_function_offset3 - location - - line343 - col8 - file0 - - ExecutedLines - - 0 - - 340 - 341 - 342 - 343 - - - - - path - - - kindcontrol - edges - - - start - - - line350 - col3 - file0 - - - line350 - col5 - file0 - - - end - - - line351 - col3 - file0 - - - line351 - col19 - file0 - - - - - - - kindevent - location - - line351 - col3 - file0 - - ranges - - - - line351 - col3 - file0 - - - line351 - col53 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindcontrol - edges - - - start - - - line352 - col3 - file0 - - - line352 - col3 - file0 - - - end - - - line352 - col6 - file0 - - - line352 - col6 - file0 - - - - - - - kindevent - location - - line352 - col6 - file0 - - ranges - - - - line352 - col4 - file0 - - - line352 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line351 - col3 - file0 - - nameTO_NULL_AND_PRINT - expansiona = 0; print( "Will this ## cause a crash?") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context6817572ced27cb7d28fc87b2aba75fb4 - issue_context_kindfunction - issue_contextmacroArgContainsHashHashInStringTest - issue_hash_function_offset3 - location - - line352 - col6 - file0 - - ExecutedLines - - 0 - - 349 - 350 - 351 - 352 - - - - - path - - - kindcontrol - edges - - - start - - - line363 - col3 - file0 - - - line363 - col5 - file0 - - - end - - - line364 - col3 - file0 - - - line364 - col11 - file0 - - - - - - - kindevent - location - - line364 - col3 - file0 - - ranges - - - - line364 - col3 - file0 - - - line364 - col23 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line365 - col3 - file0 - - - line365 - col3 - file0 - - - end - - - line365 - col8 - file0 - - - line365 - col8 - file0 - - - - - - - kindevent - location - - line365 - col8 - file0 - - ranges - - - - line365 - col4 - file0 - - - line365 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line364 - col3 - file0 - - namePRINT_STR - expansionprint("Hello"); ptr = nullptr - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contexte6947ee72df70243a3b4c9e9eaed0888 - issue_context_kindfunction - issue_contexthashOperatorTest - issue_hash_function_offset3 - location - - line365 - col8 - file0 - - ExecutedLines - - 0 - - 362 - 363 - 364 - 365 - - - - - path - - - kindcontrol - edges - - - start - - - line372 - col3 - file0 - - - line372 - col5 - file0 - - - end - - - line373 - col3 - file0 - - - line373 - col19 - file0 - - - - - - - kindevent - location - - line373 - col3 - file0 - - ranges - - - - line373 - col3 - file0 - - - line373 - col52 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'a' - message - Null pointer value stored to 'a' - - - kindcontrol - edges - - - start - - - line374 - col3 - file0 - - - line374 - col3 - file0 - - - end - - - line374 - col6 - file0 - - - line374 - col6 - file0 - - - - - - - kindevent - location - - line374 - col6 - file0 - - ranges - - - - line374 - col4 - file0 - - - line374 - col4 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'a') - message - Dereference of null pointer (loaded from variable 'a') - - - macro_expansions - - - location - - line373 - col3 - file0 - - nameTO_NULL_AND_PRINT - expansiona = 0; print( "Will this # cause a crash?") - - - descriptionDereference of null pointer (loaded from variable 'a') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_contextb1da2db423e721067ed5cfda858890be - issue_context_kindfunction - issue_contextmacroArgContainsHashInStringTest - issue_hash_function_offset3 - location - - line374 - col6 - file0 - - ExecutedLines - - 0 - - 371 - 372 - 373 - 374 - - - - - path - - - kindcontrol - edges - - - start - - - line420 - col3 - file0 - - - line420 - col5 - file0 - - - end - - - line420 - col18 - file0 - - - line420 - col43 - file0 - - - - - - - kindevent - location - - line420 - col18 - file0 - - ranges - - - - line420 - col18 - file0 - - - line420 - col49 - file0 - - - - depth0 - extended_message - Calling 'getLowestCommonDenominator' - message - Calling 'getLowestCommonDenominator' - - - kindevent - location - - line415 - col1 - file0 - - depth1 - extended_message - Entered call from 'testVeryComplexAlgorithm' - message - Entered call from 'testVeryComplexAlgorithm' - - - kindcontrol - edges - - - start - - - line415 - col1 - file0 - - - line415 - col3 - file0 - - - end - - - line416 - col3 - file0 - - - line416 - col21 - file0 - - - - - - - kindpop-up - location - - line416 - col3 - file0 - - ranges - - - - line416 - col3 - file0 - - - line416 - col27 - file0 - - - - extended_message - 'A' is >= 0 - message - 'A' is >= 0 - - - kindpop-up - location - - line416 - col3 - file0 - - ranges - - - - line416 - col3 - file0 - - - line416 - col27 - file0 - - - - extended_message - 'B' is >= 0 - message - 'B' is >= 0 - - - kindevent - location - - line416 - col3 - file0 - - ranges - - - - line416 - col3 - file0 - - - line416 - col27 - file0 - - - - depth1 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line416 - col3 - file0 - - nameEUCLIDEAN_ALGORITHM - expansionif (A<0 ){A=-A;} if ( B<0 ){ B=- B;}return B / ( B - B); - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context3484e210b755ea46d632296fffd709e0 - issue_context_kindfunction - issue_contextgetLowestCommonDenominator - issue_hash_function_offset1 - location - - line416 - col3 - file0 - - ExecutedLines - - 0 - - 415 - 416 - 419 - 420 - - - - - path - - - kindcontrol - edges - - - start - - - line435 - col3 - file0 - - - line435 - col5 - file0 - - - end - - - line436 - col3 - file0 - - - line436 - col25 - file0 - - - - - - - kindevent - location - - line436 - col3 - file0 - - ranges - - - - line436 - col3 - file0 - - - line436 - col67 - file0 - - - - depth0 - extended_message - Null pointer value stored to 'ptr' - message - Null pointer value stored to 'ptr' - - - kindcontrol - edges - - - start - - - line437 - col3 - file0 - - - line437 - col3 - file0 - - - end - - - line437 - col8 - file0 - - - line437 - col8 - file0 - - - - - - - kindevent - location - - line437 - col8 - file0 - - ranges - - - - line437 - col4 - file0 - - - line437 - col6 - file0 - - - - depth0 - extended_message - Dereference of null pointer (loaded from variable 'ptr') - message - Dereference of null pointer (loaded from variable 'ptr') - - - macro_expansions - - - location - - line436 - col3 - file0 - - nameYET_ANOTHER_SET_TO_NULL - expansionprint((void *)5); print((void *)"Remember the Vasa"); ptr = nullptr; - - - descriptionDereference of null pointer (loaded from variable 'ptr') - categoryLogic error - typeDereference of null pointer - check_namecore.NullDereference - - issue_hash_content_of_line_in_context42143f52fc9638fb2c0af41916e09d2f - issue_context_kindfunction - issue_contexttest - issue_hash_function_offset3 - location - - line437 - col8 - file0 - - ExecutedLines - - 0 - - 434 - 435 - 436 - 437 - - - - - path - - - kindcontrol - edges - - - start - - - line448 - col3 - file0 - - - line448 - col4 - file0 - - - end - - - line448 - col7 - file0 - - - line448 - col11 - file0 - - - - - - - kindevent - location - - line448 - col7 - file0 - - ranges - - - - line448 - col7 - file0 - - - line448 - col16 - file0 - - - - depth0 - extended_message - Assuming 'garbage_value' is equal to 0 - message - Assuming 'garbage_value' is equal to 0 - - - kindevent - location - - line449 - col7 - file0 - - ranges - - - - line449 - col5 - file0 - - - line449 - col13 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line448 - col7 - file0 - - namevalue - expansiongarbage_ - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context1f3c94860e67b6b863e956bd67e49f1d - issue_context_kindfunction - issue_contextrecursiveMacroUser - issue_hash_function_offset2 - location - - line449 - col7 - file0 - - ExecutedLines - - 0 - - 447 - 448 - 449 - - - - - path - - - kindcontrol - edges - - - start - - - line460 - col33 - file0 - - - line460 - col33 - file0 - - - end - - - line460 - col37 - file0 - - - line460 - col39 - file0 - - - - - - - kindevent - location - - line460 - col37 - file0 - - ranges - - - - line460 - col37 - file0 - - - line460 - col41 - file0 - - - - depth0 - extended_message - Calling 'foo' - message - Calling 'foo' - - - kindevent - location - - line459 - col1 - file0 - - depth1 - extended_message - Entered call from 'useZeroApplier1' - message - Entered call from 'useZeroApplier1' - - - kindevent - location - - line459 - col1 - file0 - - ranges - - - - line459 - col1 - file0 - - - line459 - col16 - file0 - - - - depth1 - extended_message - Returning zero - message - Returning zero - - - kindevent - location - - line460 - col37 - file0 - - ranges - - - - line460 - col37 - file0 - - - line460 - col41 - file0 - - - - depth0 - extended_message - Returning from 'foo' - message - Returning from 'foo' - - - kindcontrol - edges - - - start - - - line460 - col37 - file0 - - - line460 - col39 - file0 - - - end - - - line460 - col35 - file0 - - - line460 - col35 - file0 - - - - - - - kindevent - location - - line460 - col35 - file0 - - ranges - - - - line460 - col33 - file0 - - - line460 - col41 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line459 - col1 - file0 - - nameAPPLY_ZERO1 - expansionint foo() { return x; }(0) - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40 - issue_context_kindfunction - issue_contextuseZeroApplier1 - issue_hash_function_offset0 - location - - line460 - col35 - file0 - - ExecutedLines - - 0 - - 459 - 460 - - - - - path - - - kindcontrol - edges - - - start - - - line469 - col33 - file0 - - - line469 - col33 - file0 - - - end - - - line469 - col37 - file0 - - - line469 - col39 - file0 - - - - - - - kindevent - location - - line469 - col37 - file0 - - ranges - - - - line469 - col37 - file0 - - - line469 - col41 - file0 - - - - depth0 - extended_message - Calling 'bar' - message - Calling 'bar' - - - kindevent - location - - line468 - col1 - file0 - - depth1 - extended_message - Entered call from 'useZeroApplier2' - message - Entered call from 'useZeroApplier2' - - - kindevent - location - - line468 - col1 - file0 - - ranges - - - - line468 - col1 - file0 - - - line468 - col11 - file0 - - - - depth1 - extended_message - Returning zero - message - Returning zero - - - kindevent - location - - line469 - col37 - file0 - - ranges - - - - line469 - col37 - file0 - - - line469 - col41 - file0 - - - - depth0 - extended_message - Returning from 'bar' - message - Returning from 'bar' - - - kindcontrol - edges - - - start - - - line469 - col37 - file0 - - - line469 - col39 - file0 - - - end - - - line469 - col35 - file0 - - - line469 - col35 - file0 - - - - - - - kindevent - location - - line469 - col35 - file0 - - ranges - - - - line469 - col33 - file0 - - - line469 - col41 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line468 - col1 - file0 - - nameAPPLY_ZERO2 - expansionint bar() { return 0; } - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_contextdd82c11b436b00009e37f54b1620a728 - issue_context_kindfunction - issue_contextuseZeroApplier2 - issue_hash_function_offset0 - location - - line469 - col35 - file0 - - ExecutedLines - - 0 - - 468 - 469 - - - - - path - - - kindcontrol - edges - - - start - - - line481 - col3 - file0 - - - line481 - col5 - file0 - - - end - - - line482 - col3 - file0 - - - line482 - col10 - file0 - - - - - - - kindevent - location - - line482 - col3 - file0 - - ranges - - - - line482 - col3 - file0 - - - line482 - col28 - file0 - - - - depth0 - extended_message - The value 0 is assigned to 'x' - message - The value 0 is assigned to 'x' - - - kindevent - location - - line483 - col13 - file0 - - ranges - - - - line483 - col10 - file0 - - - line483 - col15 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line482 - col3 - file0 - - nameDISPATCH - expansionfoo(x, "LF1M healer");x = 0;; - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context0911a97774745d4fa0ac03cd9680dfe1 - issue_context_kindfunction - issue_contextmulitpleParamsResolveToVA_ARGS - issue_hash_function_offset3 - location - - line483 - col13 - file0 - - ExecutedLines - - 0 - - 480 - 481 - 482 - 483 - - - - - path - - - kindcontrol - edges - - - start - - - line494 - col3 - file0 - - - line494 - col5 - file0 - - - end - - - line495 - col3 - file0 - - - line495 - col16 - file0 - - - - - - - kindevent - location - - line495 - col3 - file0 - - ranges - - - - line495 - col3 - file0 - - - line495 - col71 - file0 - - - - depth0 - extended_message - The value 0 is assigned to 'x' - message - The value 0 is assigned to 'x' - - - kindevent - location - - line496 - col13 - file0 - - ranges - - - - line496 - col10 - file0 - - - line496 - col15 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line495 - col3 - file0 - - nameCONCAT_VA_ARGS - expansionvariadicCFunction(x, "You need to construct additional pylons.",'c', 9);x = 0; - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_contexted592fb952ed786e7efdc81bbc538e94 - issue_context_kindfunction - issue_contextconcatVA_ARGS - issue_hash_function_offset3 - location - - line496 - col13 - file0 - - ExecutedLines - - 0 - - 493 - 494 - 495 - 496 - - - - - path - - - kindcontrol - edges - - - start - - - line502 - col3 - file0 - - - line502 - col5 - file0 - - - end - - - line503 - col3 - file0 - - - line503 - col16 - file0 - - - - - - - kindevent - location - - line503 - col3 - file0 - - ranges - - - - line503 - col3 - file0 - - - line503 - col44 - file0 - - - - depth0 - extended_message - The value 0 is assigned to 'x' - message - The value 0 is assigned to 'x' - - - kindevent - location - - line504 - col13 - file0 - - ranges - - - - line504 - col10 - file0 - - - line504 - col15 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line503 - col3 - file0 - - nameCONCAT_VA_ARGS - expansionvariadicCFunction(x, "You need to construct",);x = 0; - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context4b0ab46d7a972d0a388b4bb59351480a - issue_context_kindfunction - issue_contextconcatVA_ARGSEmpty - issue_hash_function_offset3 - location - - line504 - col13 - file0 - - ExecutedLines - - 0 - - 501 - 502 - 503 - 504 - - - - - path - - - kindcontrol - edges - - - start - - - line514 - col3 - file0 - - - line514 - col5 - file0 - - - end - - - line515 - col3 - file0 - - - line515 - col21 - file0 - - - - - - - kindevent - location - - line515 - col3 - file0 - - ranges - - - - line515 - col3 - file0 - - - line515 - col71 - file0 - - - - depth0 - extended_message - The value 0 is assigned to 'x' - message - The value 0 is assigned to 'x' - - - kindevent - location - - line516 - col13 - file0 - - ranges - - - - line516 - col10 - file0 - - - line516 - col15 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line515 - col3 - file0 - - nameSTRINGIFIED_VA_ARGS - expansionvariadicCFunction(x, "Additional supply depots required.", "'a'", 10);x = 0; - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context6622e3f0651f97e6cbf4e075e6b07707 - issue_context_kindfunction - issue_contextstringifyVA_ARGS - issue_hash_function_offset3 - location - - line516 - col13 - file0 - - ExecutedLines - - 0 - - 513 - 514 - 515 - 516 - - - - - path - - - kindcontrol - edges - - - start - - - line524 - col3 - file0 - - - line524 - col5 - file0 - - - end - - - line525 - col3 - file0 - - - line525 - col21 - file0 - - - - - - - kindevent - location - - line525 - col3 - file0 - - ranges - - - - line525 - col3 - file0 - - - line525 - col62 - file0 - - - - depth0 - extended_message - The value 0 is assigned to 'x' - message - The value 0 is assigned to 'x' - - - kindevent - location - - line526 - col13 - file0 - - ranges - - - - line526 - col10 - file0 - - - line526 - col15 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line525 - col3 - file0 - - nameSTRINGIFIED_VA_ARGS - expansionvariadicCFunction(x, "Additional supply depots required.", ")";x = 0; - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context86c6e52c81f1129e6c9f51e6938d9ee7 - issue_context_kindfunction - issue_contextstringifyVA_ARGSEmpty - issue_hash_function_offset3 - location - - line526 - col13 - file0 - - ExecutedLines - - 0 - - 523 - 524 - 525 - 526 - - - - - path - - - kindcontrol - edges - - - start - - - line537 - col3 - file0 - - - line537 - col5 - file0 - - - end - - - line539 - col3 - file0 - - - line539 - col15 - file0 - - - - - - - kindevent - location - - line539 - col3 - file0 - - ranges - - - - line539 - col3 - file0 - - - line539 - col26 - file0 - - - - depth0 - extended_message - The value 0 is assigned to 'a' - message - The value 0 is assigned to 'a' - - - kindevent - location - - line540 - col13 - file0 - - ranges - - - - line540 - col10 - file0 - - - line540 - col15 - file0 - - - - depth0 - extended_message - Division by zero - message - Division by zero - - - macro_expansions - - - location - - line539 - col3 - file0 - - nameBZ44493_GNUVA - expansion--(a); - - - descriptionDivision by zero - categoryLogic error - typeDivision by zero - check_namecore.DivideZero - - issue_hash_content_of_line_in_context21c6d180d8c8c30cf730b7a7136980a9 - issue_context_kindfunction - issue_contextbz44493 - issue_hash_function_offset4 - location - - line540 - col13 - file0 - - ExecutedLines - - 0 - - 536 - 537 - 538 - 539 - 540 - - - - - files - - - - Index: clang/test/Analysis/plist-macros-with-expansion-ctu.c =================================================================== --- clang/test/Analysis/plist-macros-with-expansion-ctu.c +++ clang/test/Analysis/plist-macros-with-expansion-ctu.c @@ -2,13 +2,13 @@ // RUN: mkdir -p %t/ctudir // RUN: %clang_cc1 -emit-pch -o %t/ctudir/plist-macros-ctu.c.ast %S/Inputs/plist-macros-ctu.c // RUN: cp %S/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt %t/ctudir/externalDefMap.txt - +// // RUN: %clang_analyze_cc1 -analyzer-checker=core \ // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ // RUN: -analyzer-config ctu-dir=%t/ctudir \ // RUN: -analyzer-config expand-macros=true \ // RUN: -analyzer-output=plist-multi-file -o %t.plist -verify %s - +// // Check the macro expansions from the plist output here, to make the test more // understandable. // RUN: FileCheck --input-file=%t.plist %s @@ -23,25 +23,30 @@ F3(&X); *X = 1; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameM1 -// CHECK-NEXT: expansion*Z = (int *)0 - +// FIXME: Macro expansion for other TUs should also work. +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: void test1() { int *X; F1(&X); *X = 1; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameM -// CHECK-NEXT: expansion*X = (int *)0 + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: void test2() { int *X; F2(&X); *X = 1; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameM -// CHECK-NEXT: expansion*Y = (int *)0 + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: #define M F1(&X) @@ -50,10 +55,20 @@ M; *X = 1; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameM -// CHECK-NEXT: expansionF1(&X) -// CHECK: nameM -// CHECK-NEXT: expansion*X = (int *)0 +// Macro expansions for the main TU still works, even in CTU mode. +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line55 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameM +// CHECK-NEXT: expansionF1 (&X ) +// CHECK-NEXT: +// CHECK-NEXT: #undef M #define M F2(&X) @@ -64,10 +79,19 @@ *X = 1; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameM -// CHECK-NEXT: expansionF2(&X) -// CHECK: nameM -// CHECK-NEXT: expansion*Y = (int *)0 +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line78 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameM +// CHECK-NEXT: expansionF2 (&X ) +// CHECK-NEXT: +// CHECK-NEXT: void test_h() { int *X; @@ -75,5 +99,6 @@ *X = 1; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameM_H -// CHECK-NEXT: expansion*A = (int *)0 +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: Index: clang/test/Analysis/plist-macros-with-expansion.c =================================================================== --- /dev/null +++ clang/test/Analysis/plist-macros-with-expansion.c @@ -0,0 +1,28 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \ +// RUN: -analyzer-output=plist -o %t.plist \ +// RUN: -analyzer-config expand-macros=true -verify +// +// RUN: FileCheck --input-file=%t.plist %s + +#define STRANGE_FN(x) STRANGE_FN(x, 0) +void test_strange_macro_expansion() { + char *path; + STRANGE_FN(path); // no-crash + // expected-warning@-1 {{implicit declaration of function}} + // expected-warning@-2 {{1st function call argument is an uninitialized value}} +} + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line10 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameSTRANGE_FN(path) +// CHECK-NEXT: expansionSTRANGE_FN (path ,0) +// CHECK-NEXT: +// CHECK-NEXT: + Index: clang/test/Analysis/plist-macros-with-expansion.cpp =================================================================== --- clang/test/Analysis/plist-macros-with-expansion.cpp +++ clang/test/Analysis/plist-macros-with-expansion.cpp @@ -1,14 +1,8 @@ // RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core %s \ // RUN: -analyzer-output=plist -o %t.plist \ -// RUN: -analyzer-config expand-macros=true +// RUN: -analyzer-config expand-macros=true -verify // -// Check the actual plist output. -// RUN: %normalize_plist <%t.plist | diff -ub \ -// RUN: %S/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist - -// -// Check the macro expansions from the plist output here, to make the test more -// understandable. -// RUN: FileCheck --input-file=%t.plist %s +// RUN: FileCheck --input-file=%t.plist %s void print(const void*); @@ -25,8 +19,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameSET_PTR_VAR_TO_NULL -// CHECK-NEXT: expansionptr = 0 +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line18 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameSET_PTR_VAR_TO_NULL +// CHECK-NEXT: expansionptr =0 +// CHECK-NEXT: +// CHECK-NEXT: #define NULL 0 #define SET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO \ @@ -38,8 +43,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameSET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO -// CHECK-NEXT: expansionptr =0 +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line42 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameSET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO +// CHECK-NEXT: expansionptr =0 +// CHECK-NEXT: +// CHECK-NEXT: //===----------------------------------------------------------------------===// // Tests for function-like macro expansions. @@ -58,8 +74,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL -// CHECK-NEXT: expansionsetToNull(&ptr) +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line73 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL(&ptr) +// CHECK-NEXT: expansionsetToNull (&ptr ) +// CHECK-NEXT: +// CHECK-NEXT: #define DOES_NOTHING(x) \ { \ @@ -78,11 +105,29 @@ DEREF(a) = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL -// CHECK-NEXT: expansionsetToNull(&a) - -// CHECK: nameDEREF -// CHECK-NEXT: expansion{ int b; b = 5; } print(a); *a +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line104 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL(&a) +// CHECK-NEXT: expansionsetToNull (&a ) +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line105 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameDEREF(a) +// CHECK-NEXT: expansion{int b ;b =5;}print (a );*a +// CHECK-NEXT: +// CHECK-NEXT: //===----------------------------------------------------------------------===// // Tests for undefining and/or redifining macros. @@ -99,8 +144,19 @@ #undef WILL_UNDEF_SET_NULL_TO_PTR -// CHECK: nameWILL_UNDEF_SET_NULL_TO_PTR -// CHECK-NEXT: expansionptr = nullptr; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line141 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameWILL_UNDEF_SET_NULL_TO_PTR(ptr) +// CHECK-NEXT: expansionptr =nullptr ; +// CHECK-NEXT: +// CHECK-NEXT: #define WILL_REDIFINE_MULTIPLE_TIMES_SET_TO_NULL(ptr) \ /* Nothing */ @@ -119,8 +175,19 @@ print("This string shouldn't be in the plist file at all. Or anywhere, " \ "but here."); -// CHECK: nameWILL_REDIFINE_MULTIPLE_TIMES_SET_TO_NULL -// CHECK-NEXT: expansionptr = nullptr; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line169 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameWILL_REDIFINE_MULTIPLE_TIMES_SET_TO_NULL(ptr) +// CHECK-NEXT: expansionptr =nullptr ; +// CHECK-NEXT: +// CHECK-NEXT: #define WILL_UNDEF_SET_NULL_TO_PTR_2(ptr) \ ptr = nullptr; @@ -134,9 +201,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// TODO: Expand arguments. -// CHECK: namePASS_PTR_TO_MACRO_THAT_WILL_BE_UNDEFD -// CHECK-NEXT: expansionptr = nullptr; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line200 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: namePASS_PTR_TO_MACRO_THAT_WILL_BE_UNDEFD(ptr) +// CHECK-NEXT: expansionptr =nullptr ; +// CHECK-NEXT: +// CHECK-NEXT: #undef WILL_UNDEF_SET_NULL_TO_PTR_2 @@ -161,8 +238,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL_AND_PRINT -// CHECK-NEXT: expansiona = 0; print( "Will this , cause a crash?") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line237 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL_AND_PRINT(a, "Will this , cause a crash?") +// CHECK-NEXT: expansiona =0;print ("Will this , cause a crash?") +// CHECK-NEXT: +// CHECK-NEXT: void macroArgContainsLParenInStringTest() { int *a; @@ -170,8 +258,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL_AND_PRINT -// CHECK-NEXT: expansiona = 0; print( "Will this ( cause a crash?") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line257 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL_AND_PRINT(a, "Will this ( cause a crash?") +// CHECK-NEXT: expansiona =0;print ("Will this ( cause a crash?") +// CHECK-NEXT: +// CHECK-NEXT: void macroArgContainsRParenInStringTest() { int *a; @@ -179,8 +278,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL_AND_PRINT -// CHECK-NEXT: expansiona = 0; print( "Will this ) cause a crash?") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line277 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL_AND_PRINT(a, "Will this ) cause a crash?") +// CHECK-NEXT: expansiona =0;print ("Will this ) cause a crash?") +// CHECK-NEXT: +// CHECK-NEXT: #define CALL_FUNCTION(funcCall) \ funcCall @@ -193,8 +303,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameCALL_FUNCTION -// CHECK-NEXT: expansionsetToNull(&a) +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line302 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCALL_FUNCTION(setToNull(&a)) +// CHECK-NEXT: expansionsetToNull (&a ) +// CHECK-NEXT: +// CHECK-NEXT: void setToNullAndPrint(int **vptr, const char *str) { setToNull(vptr); @@ -207,8 +328,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameCALL_FUNCTION -// CHECK-NEXT: expansionsetToNullAndPrint(&a, "Hello!") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line327 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCALL_FUNCTION(setToNullAndPrint(&a, "Hello!")) +// CHECK-NEXT: expansionsetToNullAndPrint (&a ,"Hello!") +// CHECK-NEXT: +// CHECK-NEXT: #define CALL_FUNCTION_WITH_TWO_PARAMS(funcCall, param1, param2) \ funcCall(param1, param2) @@ -219,8 +351,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameCALL_FUNCTION_WITH_TWO_PARAMS -// CHECK-NEXT: expansionsetToNullAndPrint( &a, "Hello!") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line350 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCALL_FUNCTION_WITH_TWO_PARAMS(setToNullAndPrint, &a, "Hello!") +// CHECK-NEXT: expansionsetToNullAndPrint (&a ,"Hello!") +// CHECK-NEXT: +// CHECK-NEXT: #define CALL_LAMBDA(l) \ l() @@ -233,9 +376,30 @@ CALL_LAMBDA(([&ptr, str] () mutable { TO_NULL(&ptr); })); *ptr = 5; // expected-warning{{Dereference of null pointer}} } - -// CHECK: nameCALL_LAMBDA -// CHECK-NEXT: expansion([&ptr, str] () mutable { setToNull(&ptr); })() +// FIXME: Why does the expansion appear twice? +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line376 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCALL_LAMBDA(([&ptr, str] () mutable { TO_NULL(&ptr); })) +// CHECK-NEXT: expansion([&ptr ,str ]()mutable {setToNull (&ptr );})() +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line376 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCALL_LAMBDA(([&ptr, str] () mutable { TO_NULL(&ptr); })) +// CHECK-NEXT: expansion([&ptr ,str ]()mutable {setToNull (&ptr );})() +// CHECK-NEXT: +// CHECK-NEXT: #define PASTE_CODE(code) \ code @@ -245,15 +409,34 @@ // NOTE: If we were to add a new variable here after a comma, we'd get a // compilation error, so this test is mainly here to show that this was also // investigated. - + // // int *ptr = nullptr, a; int *ptr = nullptr; *ptr = 5; }) } -// CHECK: namePASTE_CODE -// CHECK-NEXT: expansion{ int *ptr = nullptr; *ptr = 5; } +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line408 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: namePASTE_CODE({ // expected- +// CHECK-NEXT: // NOTE: If we were to add a new variable here after a comma, we'd get a +// CHECK-NEXT: // compilation error, so this test is mainly here to show that this was also +// CHECK-NEXT: // investigated. +// CHECK-NEXT: // +// CHECK-NEXT: // int *ptr = nullptr, a; +// CHECK-NEXT: int *ptr = nullptr; +// CHECK-NEXT: *ptr = 5; +// CHECK-NEXT: }) +// CHECK-NEXT: expansion{int *ptr =nullptr ;*ptr =5;} +// CHECK-NEXT: +// CHECK-NEXT: // Example taken from // https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html#Macro-Arguments. @@ -269,8 +452,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: namePOTENTIALLY_EMPTY_PARAM -// CHECK-NEXT: expansion;ptr = nullptr +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line451 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: namePOTENTIALLY_EMPTY_PARAM(,ptr) +// CHECK-NEXT: expansion;ptr =nullptr +// CHECK-NEXT: +// CHECK-NEXT: #define NESTED_EMPTY_PARAM(a, b) \ POTENTIALLY_EMPTY_PARAM(a, b); @@ -283,8 +477,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameNESTED_EMPTY_PARAM -// CHECK-NEXT: expansion; ptr = nullptr; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line476 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameNESTED_EMPTY_PARAM(, ptr) +// CHECK-NEXT: expansion;ptr =nullptr ; +// CHECK-NEXT: +// CHECK-NEXT: #define CALL_FUNCTION_WITH_ONE_PARAM_THROUGH_MACRO(func, param) \ CALL_FUNCTION(func(param)) @@ -295,8 +500,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameCALL_FUNCTION_WITH_ONE_PARAM_THROUGH_MACRO -// CHECK-NEXT: expansionsetToNull( &ptr) +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line499 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCALL_FUNCTION_WITH_ONE_PARAM_THROUGH_MACRO(setToNull, &ptr) +// CHECK-NEXT: expansionsetToNull (&ptr ) +// CHECK-NEXT: +// CHECK-NEXT: //===----------------------------------------------------------------------===// // Tests for variadic macro arguments. @@ -315,8 +531,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameVARIADIC_SET_TO_NULL -// CHECK-NEXT: expansionptr = nullptr; variadicFunc( 1, 5, "haha!") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line530 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameVARIADIC_SET_TO_NULL(ptr, 1, 5, "haha!") +// CHECK-NEXT: expansionptr =nullptr ;variadicFunc (1,5,"haha!") +// CHECK-NEXT: +// CHECK-NEXT: void variadicMacroArgumentWithoutAnyArgumentTest() { int *ptr; @@ -326,8 +553,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameVARIADIC_SET_TO_NULL -// CHECK-NEXT: expansionptr = nullptr; variadicFunc() +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line552 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameVARIADIC_SET_TO_NULL(ptr) +// CHECK-NEXT: expansionptr =nullptr ;variadicFunc () +// CHECK-NEXT: +// CHECK-NEXT: //===----------------------------------------------------------------------===// // Tests for # and ##. @@ -343,8 +581,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameDECLARE_FUNC_AND_SET_TO_NULL -// CHECK-NEXT: expansionvoid generated_whatever(); ptr = nullptr; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line580 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameDECLARE_FUNC_AND_SET_TO_NULL(whatever, ptr) +// CHECK-NEXT: expansionvoid generated_whatever ();ptr =nullptr ; +// CHECK-NEXT: +// CHECK-NEXT: void macroArgContainsHashHashInStringTest() { int *a; @@ -352,8 +601,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL_AND_PRINT -// CHECK-NEXT: expansiona = 0; print( "Will this ## cause a crash?") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line600 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL_AND_PRINT(a, "Will this ## cause a crash?") +// CHECK-NEXT: expansiona =0;print ("Will this ## cause a crash?") +// CHECK-NEXT: +// CHECK-NEXT: #define PRINT_STR(str, ptr) \ print(#str); \ @@ -365,8 +625,19 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: namePRINT_STR -// CHECK-NEXT: expansionprint("Hello"); ptr = nullptr +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line624 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: namePRINT_STR(Hello, ptr) +// CHECK-NEXT: expansionprint ("Hello");ptr =nullptr +// CHECK-NEXT: +// CHECK-NEXT: void macroArgContainsHashInStringTest() { int *a; @@ -374,8 +645,19 @@ *a = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameTO_NULL_AND_PRINT -// CHECK-NEXT: expansiona = 0; print( "Will this # cause a crash?") +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line644 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameTO_NULL_AND_PRINT(a, "Will this # cause a crash?") +// CHECK-NEXT: expansiona =0;print ("Will this # cause a crash?") +// CHECK-NEXT: +// CHECK-NEXT: //===----------------------------------------------------------------------===// // Tests for more complex macro expansions. @@ -420,8 +702,20 @@ int tmp = 8 / (getLowestCommonDenominator(5, 7) - 1); print(&tmp); } -// CHECK: nameEUCLIDEAN_ALGORITHM -// CHECK-NEXT: expansionif (A<0 ){A=-A;} if ( B<0 ){ B=- B;}return B / ( B - B); + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line698 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameEUCLIDEAN_ALGORITHM(A, B) +// CHECK-NEXT: expansionif (A <0){A =-A ;}if (B <0){B =-B ;}return B /(B -B ); +// CHECK-NEXT: +// CHECK-NEXT: #define YET_ANOTHER_SET_TO_NULL(x, y, z) \ print((void *) x); \ @@ -436,8 +730,20 @@ YET_ANOTHER_SET_TO_NULL(5, DO_NOTHING2("Remember the Vasa"), ptr); *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// CHECK: nameYET_ANOTHER_SET_TO_NULL -// CHECK-NEXT: expansionprint((void *)5); print((void *)"Remember the Vasa"); ptr = nullptr; + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line730 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameYET_ANOTHER_SET_TO_NULL(5, DO_NOTHING2("Remember the Vasa"), ptr) +// CHECK-NEXT: expansionprint ((void *)5);print ((void *)"Remember the Vasa");ptr =nullptr ; +// CHECK-NEXT: +// CHECK-NEXT: int garbage_value; @@ -450,8 +756,19 @@ // expected-warning@-1{{expression result unused}} } -// CHECK: namevalue -// CHECK-NEXT: expansiongarbage_ +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line754 +// CHECK-NEXT: col7 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: namevalue +// CHECK-NEXT: expansiongarbage_value +// CHECK-NEXT: +// CHECK-NEXT: #define FOO(x) int foo() { return x; } #define APPLY_ZERO1(function) function(0) @@ -459,8 +776,19 @@ APPLY_ZERO1(FOO) void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}} -// CHECK: nameAPPLY_ZERO1 -// CHECK-NEXT: expansionint foo() { return x; }(0) +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line776 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameAPPLY_ZERO1(FOO) +// CHECK-NEXT: expansionint foo (){return 0;} +// CHECK-NEXT: +// CHECK-NEXT: #define BAR(x) int bar() { return x; } #define APPLY_ZERO2 BAR(0) @@ -468,8 +796,19 @@ APPLY_ZERO2 void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}} -// CHECK: nameAPPLY_ZERO2 -// CHECK-NEXT: expansionint bar() { return 0; } +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line796 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameAPPLY_ZERO2 +// CHECK-NEXT: expansionint bar (){return 0;} +// CHECK-NEXT: +// CHECK-NEXT: void foo(int &x, const char *str); @@ -482,8 +821,20 @@ DISPATCH(x, "LF1M healer"); (void)(10 / x); // expected-warning{{Division by zero}} } -// CHECK: nameDISPATCH -// CHECK-NEXT: expansionfoo(x, "LF1M healer");x = 0;; + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line821 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameDISPATCH(x, "LF1M healer") +// CHECK-NEXT: expansionfoo (x ,"LF1M healer");x =0;; +// CHECK-NEXT: +// CHECK-NEXT: void variadicCFunction(int &x, const char *str, ...); @@ -495,17 +846,40 @@ CONCAT_VA_ARGS(x, "You need to construct additional pylons.", 'c', 9); (void)(10 / x); // expected-warning{{Division by zero}} } -// CHECK: nameCONCAT_VA_ARGS -// CHECK-NEXT: expansionvariadicCFunction(x, "You need to construct additional pylons.",'c', 9);x = 0; + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line846 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCONCAT_VA_ARGS(x, "You need to construct additional pylons.", 'c', 9) +// CHECK-NEXT: expansionvariadicCFunction (x ,"You need to construct additional pylons.",'c',9);x =0; +// CHECK-NEXT: +// CHECK-NEXT: void concatVA_ARGSEmpty(void) { int x = 1; CONCAT_VA_ARGS(x, "You need to construct"); (void)(10 / x); // expected-warning{{Division by zero}} } -// FIXME: The comma shouldn't be present after the last argument. -// CHECK: nameCONCAT_VA_ARGS -// CHECK-NEXT: expansionvariadicCFunction(x, "You need to construct",);x = 0; + +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line866 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameCONCAT_VA_ARGS(x, "You need to construct") +// CHECK-NEXT: expansionvariadicCFunction (x ,"You need to construct");x =0; +// CHECK-NEXT: +// CHECK-NEXT: #define STRINGIFIED_VA_ARGS(i, fmt, ...) variadicCFunction(i, fmt, #__VA_ARGS__); \ i = 0; @@ -516,9 +890,19 @@ (void)(10 / x); // expected-warning{{Division by zero}} } -// FIXME: Stringify and escape __VA_ARGS__ correctly. -// CHECK: nameSTRINGIFIED_VA_ARGS -// CHECK-NEXT: expansionvariadicCFunction(x, "Additional supply depots required.", "'a'", 10);x = 0; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line889 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameSTRINGIFIED_VA_ARGS(x, "Additional supply depots required.", 'a', 10) +// CHECK-NEXT: expansionvariadicCFunction (x ,"Additional supply depots required.","'a', 10");x =0; +// CHECK-NEXT: +// CHECK-NEXT: void stringifyVA_ARGSEmpty(void) { int x = 1; @@ -526,9 +910,19 @@ (void)(10 / x); // expected-warning{{Division by zero}} } -// FIXME: Stringify and escape __VA_ARGS__ correctly. -// CHECK: nameSTRINGIFIED_VA_ARGS -// CHECK-NEXT: expansionvariadicCFunction(x, "Additional supply depots required.", ")";x = 0; +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line909 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameSTRINGIFIED_VA_ARGS(x, "Additional supply depots required.") +// CHECK-NEXT: expansionvariadicCFunction (x ,"Additional supply depots required.","");x =0; +// CHECK-NEXT: +// CHECK-NEXT: // bz44493: Support GNU-style named variadic arguments in plister #define BZ44493_GNUVA(i, args...) --(i); @@ -541,5 +935,16 @@ return 0; } -// CHECK: nameBZ44493_GNUVA -// CHECK-NEXT: expansion--(a); +// CHECK: macro_expansions +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line933 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: nameBZ44493_GNUVA(a, "arg2") +// CHECK-NEXT: expansion--(a ); +// CHECK-NEXT: +// CHECK-NEXT: Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp =================================================================== --- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -91,26 +91,6 @@ *Success = NewFD && NewFD->hasBody() && !OrigFDHasBody; if (NewFD) { - // Check GetImportedFromSourceLocation. - llvm::Optional> SLocResult = - CTU.getImportedFromSourceLocation(NewFD->getLocation()); - EXPECT_TRUE(SLocResult); - if (SLocResult) { - SourceLocation OrigSLoc = (*SLocResult).first; - ASTUnit *OrigUnit = (*SLocResult).second; - // OrigUnit is created internally by CTU (is not the - // ASTWithDefinition). - TranslationUnitDecl *OrigTU = - OrigUnit->getASTContext().getTranslationUnitDecl(); - const FunctionDecl *FDWithDefinition = FindFInTU(OrigTU); - EXPECT_TRUE(FDWithDefinition); - if (FDWithDefinition) { - EXPECT_EQ(FDWithDefinition->getName(), "f"); - EXPECT_TRUE(FDWithDefinition->isThisDeclarationADefinition()); - EXPECT_EQ(OrigSLoc, FDWithDefinition->getLocation()); - } - } - // Check parent map. const DynTypedNodeList ParentsAfterImport = Ctx.getParentMapContext().getParents(*FD);