Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package cvise for openSUSE:Factory checked in at 2022-09-11 21:57:47 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/cvise (Old) and /work/SRC/openSUSE:Factory/.cvise.new.2083 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "cvise" Sun Sep 11 21:57:47 2022 rev:54 rq:1002529 version:2.5.0+git.20220911.4c7ce7f Changes: -------- --- /work/SRC/openSUSE:Factory/cvise/cvise.changes 2022-09-09 18:29:50.061315281 +0200 +++ /work/SRC/openSUSE:Factory/.cvise.new.2083/cvise.changes 2022-09-11 21:57:56.113726999 +0200 @@ -1,0 +2,6 @@ +Sun Sep 11 18:48:13 UTC 2022 - mli...@suse.cz + +- Update to version 2.5.0+git.20220911.4c7ce7f: + * instantiate-template-param was not working for parameters inside anonymous templates + +------------------------------------------------------------------- Old: ---- cvise-2.5.0+git.20220909.31fe1f8.tar.xz New: ---- cvise-2.5.0+git.20220911.4c7ce7f.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ cvise.spec ++++++ --- /var/tmp/diff_new_pack.YOEoCV/_old 2022-09-11 21:57:56.593728350 +0200 +++ /var/tmp/diff_new_pack.YOEoCV/_new 2022-09-11 21:57:56.597728361 +0200 @@ -17,7 +17,7 @@ Name: cvise -Version: 2.5.0+git.20220909.31fe1f8 +Version: 2.5.0+git.20220911.4c7ce7f Release: 0 Summary: Super-parallel Python port of the C-Reduce License: BSD-3-Clause ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.YOEoCV/_old 2022-09-11 21:57:56.657728530 +0200 +++ /var/tmp/diff_new_pack.YOEoCV/_new 2022-09-11 21:57:56.661728541 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/marxin/cvise</param> - <param name="changesrevision">d825c80c973efb097258cc5fe3baac9bf8928b9b</param></service></servicedata> + <param name="changesrevision">d968def2709693b1aaba5ecb022876093972f1bd</param></service></servicedata> (No newline at EOF) ++++++ cvise-2.5.0+git.20220909.31fe1f8.tar.xz -> cvise-2.5.0+git.20220911.4c7ce7f.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/AggregateToScalar.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/AggregateToScalar.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/AggregateToScalar.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/AggregateToScalar.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -150,7 +150,7 @@ { std::string VarStr(VarName); QualType QT = RefE->getType(); - QT.getAsStringInternal(VarStr, Context->getPrintingPolicy()); + QT.getAsStringInternal(VarStr, getPrintingPolicy()); if (InitStr) { VarStr += " = "; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/BinOpSimplification.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/BinOpSimplification.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/BinOpSimplification.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/BinOpSimplification.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -169,7 +169,7 @@ setTmpVarName(VarStr); QT.getAsStringInternal(VarStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); VarStr += ";"; return RewriteHelper->addLocalVarToFunc(VarStr, TheFuncDecl); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/CMakeLists.txt new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/CMakeLists.txt --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/CMakeLists.txt 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/CMakeLists.txt 2022-09-11 20:45:54.000000000 +0200 @@ -90,6 +90,8 @@ "/tests/instantiate-template-param/test2.cc" "/tests/instantiate-template-param/test2.output" "/tests/instantiate-template-param/test3.cc" + "/tests/instantiate-template-param/test4.cc" + "/tests/instantiate-template-param/test4.output" "/tests/local-to-global/macro.c" "/tests/local-to-global/macro.output" "/tests/local-to-global/unnamed_1.c" @@ -329,6 +331,10 @@ "/tests/return-void/test6.output" "/tests/return-void/test7.cc" "/tests/return-void/test7.output" + "/tests/return-void/test8.cc" + "/tests/return-void/test8.output" + "/tests/return-void/test9.c" + "/tests/return-void/test9.output" "/tests/simplify-callexpr/macro.c" "/tests/simplify-callexpr/macro.output" "/tests/simplify-callexpr/test.c" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/CallExprToValue.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/CallExprToValue.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/CallExprToValue.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/CallExprToValue.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -129,7 +129,7 @@ NamePostfix++; CommaStr = RVStr; - RVQualType.getAsStringInternal(RVStr, Context->getPrintingPolicy()); + RVQualType.getAsStringInternal(RVStr, getPrintingPolicy()); RVStr += ";\n"; if (CurrentFD) { RewriteHelper->insertStringBeforeFunc(CurrentFD, RVStr); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ExpressionDetector.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ExpressionDetector.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ExpressionDetector.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ExpressionDetector.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -695,7 +695,7 @@ RewriteHelper->getExprString(TheExpr, ExprStr); std::string TyStr; - TheExpr->getType().getAsStringInternal(TyStr, Context->getPrintingPolicy()); + TheExpr->getType().getAsStringInternal(TyStr, getPrintingPolicy()); TmpVarName = TmpVarNamePrefix + std::to_string(TmpVarNameQueryWrap->getMaxNamePostfix()+1); Str += TyStr + " " + TmpVarName + " = " + ExprStr + ";\n"; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/InstantiateTemplateParam.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/InstantiateTemplateParam.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/InstantiateTemplateParam.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/InstantiateTemplateParam.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -315,12 +315,12 @@ case Type::Record: { RecordDeclSet TempAvailableRecordDecls; getForwardDeclStr(Ty, ForwardStr, TempAvailableRecordDecls); - QT.getAsStringInternal(Str, Context->getPrintingPolicy()); + QT.getAsStringInternal(Str, getPrintingPolicy()); return true; } case Type::Builtin: { - QT.getAsStringInternal(Str, Context->getPrintingPolicy()); + QT.getAsStringInternal(Str, getPrintingPolicy()); return true; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/LocalToGlobal.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/LocalToGlobal.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/LocalToGlobal.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/LocalToGlobal.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -200,7 +200,7 @@ else { QualType T = VD->getType(); T.getAsStringInternal(NewName, - ConsumerInstance->Context->getPrintingPolicy()); + ConsumerInstance->getPrintingPolicy()); GlobalVarStr = NewName; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/RemoveNestedFunction.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/RemoveNestedFunction.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/RemoveNestedFunction.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/RemoveNestedFunction.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -190,7 +190,7 @@ std::string ArgStr; llvm::raw_string_ostream Stream(ArgStr); - TST->getArg(0).print(Context->getPrintingPolicy(), Stream + TST->getArg(0).print(getPrintingPolicy(), Stream #if LLVM_VERSION_MAJOR >= 13 , false #endif @@ -199,7 +199,7 @@ for (unsigned I = 1; I < NumArgs; ++I) { const TemplateArgument &Arg = TST->getArg(I); Stream << ", "; - Arg.print(Context->getPrintingPolicy(), Stream + Arg.print(getPrintingPolicy(), Stream #if LLVM_VERSION_MAJOR >= 13 , false #endif @@ -216,7 +216,7 @@ void RemoveNestedFunction::getNewTmpVariable(const QualType &QT, std::string &VarStr) { - QT.getAsStringInternal(VarStr, Context->getPrintingPolicy()); + QT.getAsStringInternal(VarStr, getPrintingPolicy()); } void RemoveNestedFunction::getNewIntTmpVariable(std::string &VarStr) @@ -402,7 +402,7 @@ TransAssert(TST && "Invalid TemplateSpecialization Type!"); QT.getAsStringInternal(VarStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); return getVarStrForTemplateSpecialization(VarStr, TST); } else { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceClassWithBaseTemplateSpec.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceClassWithBaseTemplateSpec.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceClassWithBaseTemplateSpec.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceClassWithBaseTemplateSpec.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -145,7 +145,7 @@ ValidInstanceNum++; if (ValidInstanceNum == TransformationCounter) { BS->getType().getAsStringInternal(TheBaseName, - Context->getPrintingPolicy()); + getPrintingPolicy()); TheCXXRecord = CXXRD; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceDependentName.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceDependentName.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceDependentName.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceDependentName.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -132,7 +132,7 @@ if (!getTypeString(ET->getNamedType(), Str, Typename)) return; std::string TyStr = ""; - ET->getNamedType().getAsStringInternal(TyStr, Context->getPrintingPolicy()); + ET->getNamedType().getAsStringInternal(TyStr, getPrintingPolicy()); if (TyStr == Str) return; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceDependentTypedef.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceDependentTypedef.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceDependentTypedef.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceDependentTypedef.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -139,7 +139,7 @@ return; std::string TdefTyStr = ""; D->getUnderlyingType().getAsStringInternal( - TdefTyStr, Context->getPrintingPolicy()); + TdefTyStr, getPrintingPolicy()); if (Str == TdefTyStr) return; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceOneLevelTypedefType.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceOneLevelTypedefType.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceOneLevelTypedefType.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceOneLevelTypedefType.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -100,7 +100,7 @@ { std::string NewTyStr; TheTypedefDecl->getUnderlyingType().getAsStringInternal(NewTyStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); SourceRange Range = TheTypeLoc.getSourceRange(); TheRewriter.ReplaceText(Range, NewTyStr); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceSimpleTypedef.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceSimpleTypedef.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReplaceSimpleTypedef.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReplaceSimpleTypedef.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -218,7 +218,7 @@ if (ValidInstanceNum == TransformationCounter) { TheTypedefDecl = CanonicalD; CanonicalD->getUnderlyingType().getAsStringInternal(TyName, - Context->getPrintingPolicy()); + getPrintingPolicy()); } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReturnVoid.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReturnVoid.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReturnVoid.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReturnVoid.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -17,6 +17,8 @@ #include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/SourceManager.h" +#include "clang/Lex/Lexer.h" +#include "clang/Lex/Preprocessor.h" #include "TransformationManager.h" @@ -203,40 +205,206 @@ TransError = TransInternalError; } -bool RVASTVisitor::rewriteFuncDecl(FunctionDecl *FD) -{ - DeclarationNameInfo NameInfo = FD->getNameInfo(); - SourceLocation NameInfoStartLoc = NameInfo.getBeginLoc(); +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +struct ClassifiedToken { + Token T; + bool IsQualifier; + bool IsSpecifier; +}; - SourceRange FuncDefRange = FD->getSourceRange(); - SourceLocation FuncStartLoc = FuncDefRange.getBegin(); +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +static bool hasAnyNestedLocalQualifiers(QualType Type) { + bool Result = Type.hasLocalQualifiers(); + if (Type->isPointerType()) + Result = Result || hasAnyNestedLocalQualifiers( + Type->castAs<PointerType>()->getPointeeType()); + if (Type->isReferenceType()) + Result = Result || hasAnyNestedLocalQualifiers( + Type->castAs<ReferenceType>()->getPointeeType()); + return Result; +} + +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +static SourceLocation expandIfMacroId(SourceLocation Loc, + const SourceManager& SM) { + if (Loc.isMacroID()) + Loc = expandIfMacroId(SM.getImmediateExpansionRange(Loc).getBegin(), SM); + assert(!Loc.isMacroID() && + "SourceLocation must not be a macro ID after recursive expansion"); + return Loc; +} + +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +static bool isCvr(Token T) { + return T.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict); +} + +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +static bool isSpecifier(Token T) { + return T.isOneOf(tok::kw_constexpr, tok::kw_inline, tok::kw_extern, + tok::kw_static, tok::kw_friend, tok::kw_virtual); +} + +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +static llvm::Optional<ClassifiedToken> +classifyToken(const FunctionDecl& F, Preprocessor& PP, Token Tok) { + ClassifiedToken CT; + CT.T = Tok; + CT.IsQualifier = true; + CT.IsSpecifier = true; + bool ContainsQualifiers = false; + bool ContainsSpecifiers = false; + bool ContainsSomethingElse = false; + + Token End; + End.startToken(); + End.setKind(tok::eof); + SmallVector<Token, 2> Stream{ Tok, End }; + + // FIXME: do not report these token to Preprocessor.TokenWatcher. + PP.EnterTokenStream(Stream, false, /*IsReinject=*/false); + while (true) { + Token T; + PP.Lex(T); + if (T.is(tok::eof)) + break; + + bool Qual = isCvr(T); + bool Spec = isSpecifier(T); + CT.IsQualifier &= Qual; + CT.IsSpecifier &= Spec; + ContainsQualifiers |= Qual; + ContainsSpecifiers |= Spec; + ContainsSomethingElse |= !Qual && !Spec; + } + + // If the Token/Macro contains more than one type of tokens, we would need + // to split the macro in order to move parts to the trailing return type. + if (ContainsQualifiers + ContainsSpecifiers + ContainsSomethingElse > 1) + return llvm::None; + + return CT; +} + +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +llvm::Optional<SmallVector<ClassifiedToken, 8>> +ReturnVoid::classifyTokensBeforeFunctionName( + const FunctionDecl& F, const ASTContext& Ctx, const SourceManager& SM, + const LangOptions& LangOpts) { + SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM); + SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM); + // Create tokens for everything before the name of the function. + std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(BeginF); + StringRef File = SM.getBufferData(Loc.first); + const char* TokenBegin = File.data() + Loc.second; + Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(), + TokenBegin, File.end()); + Token T; + SmallVector<ClassifiedToken, 8> ClassifiedTokens; + while (!Lexer.LexFromRawLexer(T) && + SM.isBeforeInTranslationUnit(T.getLocation(), BeginNameF)) { + if (T.is(tok::raw_identifier)) { + IdentifierInfo& Info = Ctx.Idents.get( + StringRef(SM.getCharacterData(T.getLocation()), T.getLength())); + if (Info.hasMacroDefinition()) { + const MacroInfo* MI = PP->getMacroInfo(&Info); + if (!MI || MI->isFunctionLike()) { + // Cannot handle function style macros. + //diag(F.getLocation(), Message); + return llvm::None; + } + } + T.setIdentifierInfo(&Info); + T.setKind(Info.getTokenID()); + } + if (llvm::Optional<ClassifiedToken> CT = classifyToken(F, *PP, T)) + ClassifiedTokens.push_back(*CT); + else { + //diag(F.getLocation(), Message); + return llvm::None; + } + } + return ClassifiedTokens; +} - if (FuncStartLoc.isMacroID()) { - FuncStartLoc = ConsumerInstance->SrcManager->getExpansionLoc(FuncStartLoc); +// Copied from https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +SourceRange ReturnVoid::findReturnTypeAndCVSourceRange( + const FunctionDecl& F, const TypeLoc& ReturnLoc, const ASTContext& Ctx, + const SourceManager& SM, const LangOptions& LangOpts) { + // We start with the range of the return type and expand to neighboring + // qualifiers (const, volatile and restrict). + SourceRange ReturnTypeRange = F.getReturnTypeSourceRange(); + if (ReturnTypeRange.isInvalid()) { + // Happens if e.g. clang cannot resolve all includes and the return type is + // unknown. + //diag(F.getLocation(), Message); + return {}; + } + // If the return type has no local qualifiers, it's source range is accurate. + if (!hasAnyNestedLocalQualifiers(F.getReturnType())) + return ReturnTypeRange; + // Include qualifiers to the left and right of the return type. + llvm::Optional<SmallVector<ClassifiedToken, 8>> MaybeTokens = + classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts); + if (!MaybeTokens) + return {}; + const SmallVector<ClassifiedToken, 8>& Tokens = *MaybeTokens; + ReturnTypeRange.setBegin(expandIfMacroId(ReturnTypeRange.getBegin(), SM)); + ReturnTypeRange.setEnd(expandIfMacroId(ReturnTypeRange.getEnd(), SM)); + bool ExtendedLeft = false; + for (size_t I = 0; I < Tokens.size(); I++) { + // If we found the beginning of the return type, include left qualifiers. + if (!SM.isBeforeInTranslationUnit(Tokens[I].T.getLocation(), + ReturnTypeRange.getBegin()) && + !ExtendedLeft) { + assert(I <= size_t(std::numeric_limits<int>::max()) && + "Integer overflow detected"); + for (int J = static_cast<int>(I) - 1; J >= 0 && Tokens[J].IsQualifier; + J--) + ReturnTypeRange.setBegin(Tokens[J].T.getLocation()); + ExtendedLeft = true; + } + // If we found the end of the return type, include right qualifiers. + if (SM.isBeforeInTranslationUnit(ReturnTypeRange.getEnd(), + Tokens[I].T.getLocation())) { + for (size_t J = I; J < Tokens.size() && Tokens[J].IsQualifier; J++) + ReturnTypeRange.setEnd(Tokens[J].T.getLocation()); + break; + } } + assert(!ReturnTypeRange.getBegin().isMacroID() && + "Return type source range begin must not be a macro"); + assert(!ReturnTypeRange.getEnd().isMacroID() && + "Return type source range end must not be a macro"); + return ReturnTypeRange; +} - const char *FuncStartBuf = - ConsumerInstance->SrcManager->getCharacterData(FuncStartLoc); - const char *NameInfoStartBuf = - ConsumerInstance->SrcManager->getCharacterData(NameInfoStartLoc); - if (FuncStartBuf == NameInfoStartBuf) { +bool RVASTVisitor::rewriteFuncDecl(FunctionDecl *FD) +{ + const TypeSourceInfo* TSI = FD->getTypeSourceInfo(); + if (TSI == nullptr) + return true; + + // It is unbelievably difficult to determine the location of the return type including the const/volatile qualifiers + SourceRange ReturnRange = ConsumerInstance->findReturnTypeAndCVSourceRange(*FD, TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>(), *ConsumerInstance->Context, *ConsumerInstance->SrcManager, ConsumerInstance->Context->getLangOpts()); + if (ReturnRange.isInvalid()) { ConsumerInstance->Rewritten = true; - return !(ConsumerInstance->TheRewriter.InsertText(FuncStartLoc, "void ")); + return !(ConsumerInstance->TheRewriter.InsertText(FD->getSourceRange().getBegin(), "void ")); } - int Offset = NameInfoStartBuf - FuncStartBuf; + SourceLocation BeginLoc = ReturnRange.getBegin(); + SourceLocation EndLoc = ReturnRange.getEnd(); - NameInfoStartBuf--; - while ((*NameInfoStartBuf == '(') || (*NameInfoStartBuf == ' ') || - (*NameInfoStartBuf == '\t') || (*NameInfoStartBuf == '\n')) { - Offset--; - NameInfoStartBuf--; - } + if (BeginLoc.isMacroID()) + BeginLoc = ConsumerInstance->SrcManager->getExpansionLoc(BeginLoc); + if (EndLoc.isMacroID()) + EndLoc = ConsumerInstance->SrcManager->getExpansionLoc(EndLoc); + + if (!Rewriter::isRewritable(BeginLoc) || !Rewriter::isRewritable(EndLoc)) + return true; - TransAssert(Offset >= 0); ConsumerInstance->Rewritten = true; - return !(ConsumerInstance->TheRewriter.ReplaceText(FuncStartLoc, - Offset, "void ")); + return !(ConsumerInstance->TheRewriter.ReplaceText(SourceRange(BeginLoc, EndLoc), "void ")); } bool RVASTVisitor::rewriteReturnStmt(ReturnStmt *RS) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReturnVoid.h new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReturnVoid.h --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/ReturnVoid.h 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/ReturnVoid.h 2022-09-11 20:45:54.000000000 +0200 @@ -24,6 +24,7 @@ class RVASTVisitor; class RVCollectionVisitor; +struct ClassifiedToken; class ReturnVoid : public Transformation { friend class RVASTVisitor; @@ -54,6 +55,15 @@ bool isInTheFuncDef(clang::ReturnStmt *RS); + llvm::Optional<llvm::SmallVector<ClassifiedToken, 8>> + classifyTokensBeforeFunctionName( + const clang::FunctionDecl& F, const clang::ASTContext& Ctx, const clang::SourceManager& SM, + const clang::LangOptions& LangOpts); + + clang::SourceRange findReturnTypeAndCVSourceRange( + const clang::FunctionDecl& F, const clang::TypeLoc& ReturnLoc, const clang::ASTContext& Ctx, + const clang::SourceManager& SM, const clang::LangOptions& LangOpts); + RVCollectionVisitor *CollectionVisitor; RVASTVisitor *TransformationASTVisitor; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/SimpleInliner.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/SimpleInliner.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/SimpleInliner.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/SimpleInliner.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -414,7 +414,7 @@ TmpVarName = getNewTmpName(); std::string VarStr = TmpVarName; CurrentFD->getReturnType().getAsStringInternal(VarStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); VarStr += ";"; RewriteHelper->addLocalVarToFunc(VarStr, TheCaller); } @@ -447,17 +447,17 @@ std::string TmpName = getNewTmpName(); std::string NewParmStr = TmpName; PD->getType().getAsStringInternal(NewParmStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); ParmsWithNameClash.push_back(NewParmStr + " = " + ArgStr + ";\n"); ArgStr = TmpName; } PD->getType().getAsStringInternal(ParmStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); ParmStr += " = " + ArgStr; } else { PD->getType().getAsStringInternal(ParmStr, - Context->getPrintingPolicy()); + getPrintingPolicy()); } ParmStr += ";\n"; ParmStrings.push_back(ParmStr); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/SimplifyCallExpr.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/SimplifyCallExpr.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/SimplifyCallExpr.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/SimplifyCallExpr.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -127,7 +127,7 @@ NamePostfix++; std::string TmpVarStr = Str; - Arg->getType().getAsStringInternal(TmpVarStr, Context->getPrintingPolicy()); + Arg->getType().getAsStringInternal(TmpVarStr, getPrintingPolicy()); TmpVarStr += ";\n"; if (CurrentFD) { RewriteHelper->insertStringBeforeFunc(CurrentFD, TmpVarStr); @@ -168,7 +168,7 @@ NamePostfix++; CommaStr += ("," + RVStr); - RVQualType.getAsStringInternal(RVStr, Context->getPrintingPolicy()); + RVQualType.getAsStringInternal(RVStr, getPrintingPolicy()); RVStr += ";\n"; if (CurrentFD) { RewriteHelper->insertStringBeforeFunc(CurrentFD, RVStr); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/Transformation.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/Transformation.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/Transformation.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/Transformation.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -942,7 +942,7 @@ if (Arg.getKind() != TemplateArgument::Type) return false; QualType ArgQT = Arg.getAsType(); - ArgQT.getAsStringInternal(Str, Context->getPrintingPolicy()); + ArgQT.getAsStringInternal(Str, getPrintingPolicy()); Str += "::"; Str += IdInfo->getName(); Typename = true; @@ -963,7 +963,7 @@ if (Arg.getKind() != TemplateArgument::Type) return false; QualType ArgQT = Arg.getAsType(); - ArgQT.getAsStringInternal(Str, Context->getPrintingPolicy()); + ArgQT.getAsStringInternal(Str, getPrintingPolicy()); return true; } @@ -1077,7 +1077,7 @@ case Type::Record: case Type::Builtin: { // fall-through - QT.getAsStringInternal(Str, Context->getPrintingPolicy()); + QT.getAsStringInternal(Str, getPrintingPolicy()); return true; } @@ -1137,6 +1137,15 @@ return SemiLoc.isInvalid(); } +clang::PrintingPolicy Transformation::getPrintingPolicy() const { + clang::PrintingPolicy Policy = Context->getPrintingPolicy(); + + // Do not output (anonymous namespace):: + Policy.SuppressUnwrittenScope = true; + + return Policy; +} + Transformation::~Transformation(void) { RewriteUtils::Finalize(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/Transformation.h new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/Transformation.h --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/Transformation.h 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/Transformation.h 2022-09-11 20:45:54.000000000 +0200 @@ -16,6 +16,7 @@ #include <cassert> #include "llvm/ADT/SmallPtrSet.h" #include "clang/AST/ASTConsumer.h" +#include "clang/AST/PrettyPrinter.h" #include "clang/Rewrite/Core/Rewriter.h" #include "RewriteUtils.h" @@ -129,6 +130,10 @@ ToCounter = Counter; } + void setPreprocessor(clang::Preprocessor* PP) { + this->PP = PP; + } + void setWarnOnCounterOutOfBounds(bool Flag) { WarnOnCounterOutOfBounds = Flag; } @@ -316,6 +321,8 @@ bool isDeclaringRecordDecl(const clang::RecordDecl *RD); + clang::PrintingPolicy getPrintingPolicy() const; + // If the location is a MacroID, get its expansion location. // Otherwise, just return the location. clang::SourceLocation getRealLocation(clang::SourceLocation Loc) const; @@ -332,6 +339,8 @@ clang::SourceManager *SrcManager; + clang::Preprocessor *PP; + clang::Rewriter TheRewriter; TransformationError TransError; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/TransformationManager.cpp new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/TransformationManager.cpp --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/TransformationManager.cpp 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/TransformationManager.cpp 2022-09-11 20:45:54.000000000 +0200 @@ -339,6 +339,7 @@ CurrentTransformationImpl->setWarnOnCounterOutOfBounds(WarnOnCounterOutOfBounds); CurrentTransformationImpl->setQueryInstanceFlag(QueryInstanceOnly); CurrentTransformationImpl->setTransformationCounter(TransformationCounter); + CurrentTransformationImpl->setPreprocessor(&ClangInstance->getPreprocessor()); if (ToCounter > 0) { if (CurrentTransformationImpl->isMultipleRewritesEnabled()) { CurrentTransformationImpl->setToCounter(ToCounter); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/instantiate-template-param/test4.cc new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/instantiate-template-param/test4.cc --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/instantiate-template-param/test4.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/instantiate-template-param/test4.cc 2022-09-11 20:45:54.000000000 +0200 @@ -0,0 +1,14 @@ +// Check that h is not replaced by "(anonymous namespace)::k" + +namespace { +struct k { +}; +} + +template <class h> struct G { + using ac = h; +}; + +int main() { + G<k> v; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/instantiate-template-param/test4.output new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/instantiate-template-param/test4.output --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/instantiate-template-param/test4.output 1970-01-01 01:00:00.000000000 +0100 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/instantiate-template-param/test4.output 2022-09-11 20:45:54.000000000 +0200 @@ -0,0 +1,14 @@ +// Check that h is not replaced by "(anonymous namespace)::k" + +namespace { +struct k { +}; +} + +template <class h> struct G { + using ac = k; +}; + +int main() { + G<k> v; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test8.cc new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test8.cc --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test8.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test8.cc 2022-09-11 20:45:54.000000000 +0200 @@ -0,0 +1,7 @@ + +class test { + int f(); +} + +int test::f() { +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test8.output new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test8.output --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test8.output 1970-01-01 01:00:00.000000000 +0100 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test8.output 2022-09-11 20:45:54.000000000 +0200 @@ -0,0 +1,7 @@ + +class test { + void f(); +} + +void test::f() { +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test9.c new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test9.c --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test9.c 1970-01-01 01:00:00.000000000 +0100 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test9.c 2022-09-11 20:45:54.000000000 +0200 @@ -0,0 +1,2 @@ + +static int keep_static_keyword(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test9.output new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test9.output --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/return-void/test9.output 1970-01-01 01:00:00.000000000 +0100 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/return-void/test9.output 2022-09-11 20:45:54.000000000 +0200 @@ -0,0 +1,2 @@ + +static void keep_static_keyword(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/test_clang_delta.py new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/test_clang_delta.py --- old/cvise-2.5.0+git.20220909.31fe1f8/clang_delta/tests/test_clang_delta.py 2022-09-09 15:02:16.000000000 +0200 +++ new/cvise-2.5.0+git.20220911.4c7ce7f/clang_delta/tests/test_clang_delta.py 2022-09-11 20:45:54.000000000 +0200 @@ -120,6 +120,9 @@ self.check_query_instances('instantiate-template-param/test3.cc', '--query-instances=instantiate-template-param', 'Available transformation instances: 0') + def test_instantiate_template_param_default_test4(self): + self.check_clang_delta('instantiate-template-param/test4.cc', '--transformation=instantiate-template-param --counter=1') + def test_local_to_global_macro(self): self.check_clang_delta('local-to-global/macro.c', '--transformation=local-to-global --counter=1') @@ -504,6 +507,12 @@ def test_return_void_test7(self): self.check_clang_delta('return-void/test7.cc', '--transformation=return-void --counter=1') + def test_return_void_test8(self): + self.check_clang_delta('return-void/test8.cc', '--transformation=return-void --counter=1') + + def test_return_void_test9(self): + self.check_clang_delta('return-void/test9.c', '--transformation=return-void --counter=1') + def test_simplify_callexpr_macro(self): self.check_clang_delta('simplify-callexpr/macro.c', '--transformation=simplify-callexpr --counter=1')