pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] WIP: devel/creduce: update for newer llvm



The attached patch makes some progress toward updating devel/creduce
for newer llvm, based on some patches posted on upstream's github and
further work myself.

It's not done yet -- it still doesn't build with newer creduce.  But
it's a start.  I'm just done for today.

It might be worthwhile to grab more patches from cvise's clang_delta
instead of working more on creduce's clang_delta piecemeal:

https://github.com/marxin/cvise/tree/master/clang_delta

Meanwhile, it may also be worthwhile to version lang/llvm, but the
number of packages requiring this is dwindling, I think, so it might
be less effort to just finish up devel/creduce (and pull up the
changes for that, woboq_codebrowser, and whatever else I already
forgot about).
From 337af0813c44cd12f704291f9ad7c3798f87354c Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Sat, 25 Jan 2025 11:55:35 +0000
Subject: [PATCH] WIP: devel/creduce: Bring this up to date with llvm>=18.

Unfinished!  Next error is:

RewriteUtils.cpp: In member function 'bool RewriteUtils::removeVarFromDeclStmt(clang::DeclStmt*, const clang::VarDecl*, clang::Decl*, bool, bool*)':
RewriteUtils.cpp:540:58: error: use of deleted function 'clang::DeclGroup::DeclGroup(const clang::DeclGroup&)'
  540 |       DeclGroup DGroup = DS->getDeclGroup().getDeclGroup();
      |                                                          ^
In file included from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/Stmt.h:17,
                 from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/Expr.h:24,
                 from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/DeclCXX.h:22,
                 from RewriteUtils.cpp:22:
/home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/DeclGroup.h:25:7: note: 'clang::DeclGroup::DeclGroup(const clang::DeclGroup&)' is implicitly deleted because the default definition would be ill-formed:
   25 | class DeclGroup final : private llvm::TrailingObjects<DeclGroup, Decl *> {
      |       ^~~~~~~~~
/home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/DeclGroup.h:25:7: error: use of deleted function 'llvm::TrailingObjects<BaseTy, TrailingTys>::TrailingObjects(const llvm::TrailingObjects<BaseTy, TrailingTys>&) [with BaseTy = clang::DeclGroup; TrailingTys = {clang::Decl*}]'
In file included from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/Type.h:47,
                 from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/DeclarationName.h:16,
                 from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/DeclBase.h:18,
                 from /home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/clang/AST/Decl.h:20,
                 from RewriteUtils.cpp:21:
/home/riastradh/pkgsrc/current/work/devel/creduce/work/.buildlink/include/llvm/Support/TrailingObjects.h:332:3: note: declared here
  332 |   TrailingObjects(const TrailingObjects &) = delete;
      |   ^~~~~~~~~~~~~~~
---
 devel/creduce/Makefile                        |  6 +-
 devel/creduce/distinfo                        | 11 ++-
 ...g__delta_CommonRenameClassRewriteVisitor.h | 10 +++
 .../patch-clang__delta_ExpressionDetector.cpp | 76 +++++++++++++++++++
 .../patch-clang__delta_RemoveNamespace.cpp    | 12 +++
 ...atch-clang__delta_RemoveNestedFunction.cpp | 31 ++++++++
 ...atch-clang__delta_RemoveUnusedFunction.cpp | 30 ++++++++
 ...h-clang__delta_RemoveUnusedStructField.cpp | 15 ++++
 .../patch-clang__delta_RenameCXXMethod.cpp    | 16 ++++
 ...atch-clang__delta_ReplaceDependentName.cpp | 24 ++++++
 ...h-clang__delta_ReplaceDependentTypedef.cpp | 15 ++++
 11 files changed, 239 insertions(+), 7 deletions(-)
 create mode 100644 devel/creduce/patches/patch-clang__delta_ExpressionDetector.cpp
 create mode 100644 devel/creduce/patches/patch-clang__delta_RemoveNestedFunction.cpp
 create mode 100644 devel/creduce/patches/patch-clang__delta_RemoveUnusedFunction.cpp
 create mode 100644 devel/creduce/patches/patch-clang__delta_RemoveUnusedStructField.cpp
 create mode 100644 devel/creduce/patches/patch-clang__delta_RenameCXXMethod.cpp
 create mode 100644 devel/creduce/patches/patch-clang__delta_ReplaceDependentName.cpp
 create mode 100644 devel/creduce/patches/patch-clang__delta_ReplaceDependentTypedef.cpp

diff --git a/devel/creduce/Makefile b/devel/creduce/Makefile
index 8fc7ae303196..913d435bec01 100644
--- a/devel/creduce/Makefile
+++ b/devel/creduce/Makefile
@@ -1,7 +1,7 @@
 # $NetBSD: Makefile,v 1.30 2024/11/14 22:19:18 wiz Exp $
 
 DISTNAME=	creduce-2.10.0
-PKGREVISION=	18
+PKGREVISION=	19
 CATEGORIES=	devel
 MASTER_SITES=	https://embed.cs.utah.edu/creduce/
 
@@ -17,10 +17,6 @@ DEPENDS+=	p5-Term-ReadKey-[0-9]*:../../devel/p5-Term-ReadKey
 DEPENDS+=	p5-Sys-CPU-[0-9]*:../../sysutils/p5-Sys-CPU
 DEPENDS+=	p5-Regexp-Common-[0-9]*:../../textproc/p5-Regexp-Common
 
-BROKEN=		"Needs to be updated to work with llvm-13.0.0"
-# https://github.com/csmith-project/creduce/issues/232
-# llvm 16 pending: https://github.com/csmith-project/creduce/pull/254
-
 USE_LANGUAGES=	c c++14
 USE_TOOLS+=	flex perl:run gmake
 GNU_CONFIGURE=	yes
diff --git a/devel/creduce/distinfo b/devel/creduce/distinfo
index 982d58e3cf56..50f19a8b52b7 100644
--- a/devel/creduce/distinfo
+++ b/devel/creduce/distinfo
@@ -3,8 +3,15 @@ $NetBSD: distinfo,v 1.11 2021/10/26 10:14:28 nia Exp $
 BLAKE2s (creduce-2.10.0.tar.gz) = 3eec6a8e9380c8b6d8b48ed1191aeb17a63982900cbd733a857396a17ed6f6b0
 SHA512 (creduce-2.10.0.tar.gz) = f2f2cc498cbf78331ea62e533579c84042ddc1ad8eb146adeae6b3a833e0ea4bb26a4ab5f1f61a30500a5a0c9c89cc1d4e4c8547aa9e4a14d3b5d744aeb4f6a7
 Size (creduce-2.10.0.tar.gz) = 779318 bytes
-SHA1 (patch-clang__delta_CommonRenameClassRewriteVisitor.h) = 66527a9c3e0bf8ff778c9a57eb20cda596223300
-SHA1 (patch-clang__delta_RemoveNamespace.cpp) = 82eb6a625a27edfac93d5727c5dde7d1382d68bb
+SHA1 (patch-clang__delta_CommonRenameClassRewriteVisitor.h) = 691d6593bb7b28cabb2bf6010ea5a87b8551e802
+SHA1 (patch-clang__delta_ExpressionDetector.cpp) = 191385bae37a4f30b063a5b532e96a68915d45ba
+SHA1 (patch-clang__delta_RemoveNamespace.cpp) = ad8b382b0f6b03b45ef9598abcbf106d6b222c78
+SHA1 (patch-clang__delta_RemoveNestedFunction.cpp) = c65bd7c9dae837025e4eafad13612d7994e9fe38
+SHA1 (patch-clang__delta_RemoveUnusedFunction.cpp) = cf545f8261a8c035e6e36a698dcfc7a8c89e5557
+SHA1 (patch-clang__delta_RemoveUnusedStructField.cpp) = c2917eda2a7f3185726f0353e6680aba9478d0db
+SHA1 (patch-clang__delta_RenameCXXMethod.cpp) = d055ac1b6492bbde7faa4ff829bb8b323ce24227
+SHA1 (patch-clang__delta_ReplaceDependentName.cpp) = 12159d0de217c2ab07027904a5ef0a430b5e984c
+SHA1 (patch-clang__delta_ReplaceDependentTypedef.cpp) = 403eeff0911015809cf10f801a27924427da75c5
 SHA1 (patch-clang__delta_RewriteUtils.cpp) = 56b8f4d19189019c4dcc83b315a1cfd2ff459955
 SHA1 (patch-clang__delta_Transformation.cpp) = b04a80569552639c529251dc450defefbd8f2e93
 SHA1 (patch-clang__delta_TransformationManager.cpp) = 322e64726dc0301832824caf228da6faf8bb6ae8
diff --git a/devel/creduce/patches/patch-clang__delta_CommonRenameClassRewriteVisitor.h b/devel/creduce/patches/patch-clang__delta_CommonRenameClassRewriteVisitor.h
index 5bd719a0f82a..b52fc4b7bf7b 100644
--- a/devel/creduce/patches/patch-clang__delta_CommonRenameClassRewriteVisitor.h
+++ b/devel/creduce/patches/patch-clang__delta_CommonRenameClassRewriteVisitor.h
@@ -22,3 +22,13 @@ Build fix for llvm 12.0.1 from https://github.com/csmith-project/creduce/tree/ll
    std::string Name;
    if (getNewNameByName(IdName, Name)) {
      SourceLocation LocStart = DTSLoc.getTemplateNameLoc();
+@@ -413,8 +413,7 @@ bool CommonRenameClassRewriteVisitor<T>:
+     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
+ 
+   case TemplateArgument::Pack:
+-    return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
+-                                                  Arg.pack_size());
++    return getDerived().TraverseTemplateArguments(Arg.pack_elements());
+   }
+ 
+   return true;
diff --git a/devel/creduce/patches/patch-clang__delta_ExpressionDetector.cpp b/devel/creduce/patches/patch-clang__delta_ExpressionDetector.cpp
new file mode 100644
index 000000000000..e86ae0b4cdda
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_ExpressionDetector.cpp
@@ -0,0 +1,76 @@
+$NetBSD$
+
+Build fix for newer llvm:
+https://github.com/csmith-project/creduce/issues/276
+
+--- clang_delta/ExpressionDetector.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/ExpressionDetector.cpp
+@@ -62,7 +62,7 @@ public:
+   virtual void InclusionDirective(SourceLocation HashLoc,
+                           const Token &IncludeTok,
+                           StringRef FileName, bool IsAngled,
+-                          CharSourceRange FilenameRange, const FileEntry *File,
++                          CharSourceRange FilenameRange, OptionalFileEntryRef File,
+                           StringRef SearchPath, StringRef RelativePath,
+                           const Module *Imported,
+                           SrcMgr::CharacteristicKind FileType) override;
+@@ -82,7 +82,7 @@ void IncludesPPCallbacks::InclusionDirec
+                                              StringRef FileName,
+                                             bool /*IsAngled*/,
+                                              CharSourceRange /*FilenameRange*/,
+-                                             const FileEntry * /*File*/,
++                                             OptionalFileEntryRef /*File*/,
+                                              StringRef /*SearchPath*/,
+                                              StringRef /*RelativePath*/,
+                                              const Module * /*Imported*/,
+@@ -118,7 +118,7 @@ bool LocalTmpVarCollector::VisitDeclRefE
+   const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl());
+   if (!VD)
+     return true;
+-  if (VD->getName().startswith(Prefix))
++  if (VD->getName().starts_with(Prefix))
+     TmpVars.push_back(VD);
+   return true;
+ }
+@@ -363,7 +363,7 @@ void ExpressionDetector::addOneTempVar(c
+ {
+   if (!VD)
+     return;
+-  if (!VD->getName().startswith(TmpVarNamePrefix))
++  if (!VD->getName().starts_with(TmpVarNamePrefix))
+     return;
+   if (const Expr *E = VD->getInit())
+     ProcessedExprs[VD] = E->IgnoreParenImpCasts();
+@@ -374,9 +374,9 @@ bool ExpressionDetector::refToTmpVar(con
+   StringRef Name = ND->getName();
+   // We don't want to repeatly replace temporary variables
+   // __creduce_expr_tmp_xxx, __creduce_printed_yy and __creduce_checked_zzz.
+-  return Name.startswith(TmpVarNamePrefix) ||
+-         Name.startswith(PrintedVarNamePrefix) ||
+-         Name.startswith(CheckedVarNamePrefix);
++  return Name.starts_with(TmpVarNamePrefix) ||
++         Name.starts_with(PrintedVarNamePrefix) ||
++         Name.starts_with(CheckedVarNamePrefix);
+ }
+ 
+ // Reference: IdenticalExprChecker.cpp from Clang
+@@ -524,8 +524,8 @@ bool ExpressionDetector::isValidExpr(Stm
+       if (const DeclRefExpr *SubE =
+           dyn_cast<DeclRefExpr>(UO->getSubExpr()->IgnoreParenCasts())) {
+         StringRef SubEName = SubE->getDecl()->getName();
+-        if (SubEName.startswith(PrintedVarNamePrefix) ||
+-            SubEName.startswith(CheckedVarNamePrefix))
++        if (SubEName.starts_with(PrintedVarNamePrefix) ||
++            SubEName.starts_with(CheckedVarNamePrefix))
+           return false;
+       }
+     }
+@@ -541,7 +541,7 @@ bool ExpressionDetector::isValidExpr(Stm
+       bool IsLit = SC == Stmt::IntegerLiteralClass ||
+                    SC == Stmt::FloatingLiteralClass;
+       if (IsLit && DRE &&
+-          DRE->getDecl()->getName().startswith(TmpVarNamePrefix) &&
++          DRE->getDecl()->getName().starts_with(TmpVarNamePrefix) &&
+           S->getStmtClass() == Stmt::IfStmtClass) {
+         return false;
+       }
diff --git a/devel/creduce/patches/patch-clang__delta_RemoveNamespace.cpp b/devel/creduce/patches/patch-clang__delta_RemoveNamespace.cpp
index a2e6bf4e644c..f82fb7b3df00 100644
--- a/devel/creduce/patches/patch-clang__delta_RemoveNamespace.cpp
+++ b/devel/creduce/patches/patch-clang__delta_RemoveNamespace.cpp
@@ -13,3 +13,15 @@ Build fix for llvm 12.0.1 from https://github.com/csmith-project/creduce/tree/ll
    std::string Name;
  
    // FIXME:
+@@ -786,7 +786,10 @@ void RemoveNamespace::handleOneUsingShad
+     return;
+ 
+   std::string NewName;
+-  const UsingDecl *D = UD->getUsingDecl();
++  const BaseUsingDecl *BD = UD->getIntroducer();
++  const UsingDecl *D = dyn_cast<UsingDecl>(BD);
++  if (!D)
++    return;
+ 
+   NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
+   NestedNameSpecifier *NNS = QualifierLoc.getNestedNameSpecifier();
diff --git a/devel/creduce/patches/patch-clang__delta_RemoveNestedFunction.cpp b/devel/creduce/patches/patch-clang__delta_RemoveNestedFunction.cpp
new file mode 100644
index 000000000000..e52729853f50
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_RemoveNestedFunction.cpp
@@ -0,0 +1,31 @@
+$NetBSD$
+
+Build fix for newer llvm.
+
+--- clang_delta/RemoveNestedFunction.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/RemoveNestedFunction.cpp
+@@ -183,19 +183,20 @@ void RemoveNestedFunction::getVarStrForT
+        std::string &VarStr,
+        const TemplateSpecializationType *TST)
+ {
+-  unsigned NumArgs = TST->getNumArgs();
++  unsigned NumArgs = TST->template_arguments().size();
+   if (NumArgs == 0) {
+     return;
+   }
+ 
+   std::string ArgStr;
+   llvm::raw_string_ostream Stream(ArgStr);
+-  TST->getArg(0).print(Context->getPrintingPolicy(), Stream);
++  TST->template_arguments()[0].print(Context->getPrintingPolicy(), Stream,
++                       /*IncludeType*/ true);
+ 
+   for (unsigned I = 1; I < NumArgs; ++I) {
+-    const TemplateArgument &Arg = TST->getArg(I);
++    const TemplateArgument &Arg = TST->template_arguments()[I];
+     Stream << ", ";
+-    Arg.print(Context->getPrintingPolicy(), Stream);
++    Arg.print(Context->getPrintingPolicy(), Stream, /*IncludeType*/ true);
+   }
+   size_t BeginPos = VarStr.find_first_of('<');
+   size_t EndPos = VarStr.find_last_of('>');
diff --git a/devel/creduce/patches/patch-clang__delta_RemoveUnusedFunction.cpp b/devel/creduce/patches/patch-clang__delta_RemoveUnusedFunction.cpp
new file mode 100644
index 000000000000..fd39964e25ae
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_RemoveUnusedFunction.cpp
@@ -0,0 +1,30 @@
+$NetBSD$
+
+Build fix for newer llvm.
+
+--- clang_delta/RemoveUnusedFunction.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/RemoveUnusedFunction.cpp
+@@ -215,9 +215,9 @@ bool RUFAnalysisVisitor::VisitFunctionDe
+       FD->getDependentSpecializationInfo();
+     // don't need to track all specs, just associate FD with one
+     // of those
+-    if (Info->getNumTemplates() > 0) {
++    if (Info->getCandidates().size() > 0) {
+       const FunctionDecl *Member =
+-        Info->getTemplate(0)->getTemplatedDecl();
++        Info->getCandidates()[0]->getTemplatedDecl();
+       ConsumerInstance->addOneMemberSpecialization(FD, Member);
+     }
+     return true;
+@@ -890,9 +890,9 @@ void RemoveUnusedFunction::handleOneFunc
+       TheFD->getDependentSpecializationInfo();
+     // don't need to track all specs, just associate FD with one
+     // of those
+-    if (Info->getNumTemplates() > 0) {
++    if (Info->getCandidates().size() > 0) {
+       const FunctionDecl *Member =
+-        Info->getTemplate(0)->getTemplatedDecl();
++        Info->getCandidates()[0]->getTemplatedDecl();
+       createFuncToExplicitSpecs(Member);
+     }
+     return;
diff --git a/devel/creduce/patches/patch-clang__delta_RemoveUnusedStructField.cpp b/devel/creduce/patches/patch-clang__delta_RemoveUnusedStructField.cpp
new file mode 100644
index 000000000000..d66f9eda4796
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_RemoveUnusedStructField.cpp
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Build fix for llvm>=17.
+
+--- clang_delta/RemoveUnusedStructField.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/RemoveUnusedStructField.cpp
+@@ -247,7 +247,7 @@ const Expr *RemoveUnusedStructField::get
+       }
+       else {
+         const DesignatedInitExpr::Designator *DS = DIE->getDesignator(0);
+-        const FieldDecl *CurrFD = DS->getField();
++        const FieldDecl *CurrFD = DS->getFieldDecl();
+         if ((CurrFD && FD == CurrFD) ||
+             (CurrFD == NULL && DS->getFieldName() == FD->getIdentifier())) {
+           IsFirstField = (I == 0);
diff --git a/devel/creduce/patches/patch-clang__delta_RenameCXXMethod.cpp b/devel/creduce/patches/patch-clang__delta_RenameCXXMethod.cpp
new file mode 100644
index 000000000000..37c091518c25
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_RenameCXXMethod.cpp
@@ -0,0 +1,16 @@
+$NetBSD$
+
+Build fix for newer llvm:
+https://github.com/csmith-project/creduce/issues/276
+
+--- clang_delta/RenameCXXMethod.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/RenameCXXMethod.cpp
+@@ -426,7 +426,7 @@ bool RenameCXXMethod::isValidName(const 
+ {
+   size_t PrefixLen = MethodNamePrefix.length();
+   StringRef NamePrefix = Name.substr(0, PrefixLen);
+-  if (!NamePrefix.equals(MethodNamePrefix))
++  if (NamePrefix != MethodNamePrefix)
+     return false;
+   llvm::APInt Num;
+   return !Name.drop_front(PrefixLen).getAsInteger(10, Num);
diff --git a/devel/creduce/patches/patch-clang__delta_ReplaceDependentName.cpp b/devel/creduce/patches/patch-clang__delta_ReplaceDependentName.cpp
new file mode 100644
index 000000000000..05527a69d016
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_ReplaceDependentName.cpp
@@ -0,0 +1,24 @@
+$NetBSD$
+
+Build fix for newer llvm.
+
+--- clang_delta/ReplaceDependentName.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/ReplaceDependentName.cpp
+@@ -120,7 +120,7 @@ void ReplaceDependentName::handleOneElab
+     return;
+ 
+   const ElaboratedType *ET = TLoc.getTypePtr();
+-  if ((ET->getKeyword() != ETK_Typename) && (ET->getKeyword() != ETK_None))
++  if ((ET->getKeyword() != ElaboratedTypeKeyword::Typename) && (ET->getKeyword() != ElaboratedTypeKeyword::None))
+     return;
+ 
+   if (TLoc.getQualifierLoc().getBeginLoc().isInvalid())
+@@ -155,7 +155,7 @@ void ReplaceDependentName::handleOneDepe
+   const DependentNameType *DNT = 
+     dyn_cast<DependentNameType>(TLoc.getTypePtr());
+   TransAssert(DNT && "NULL DependentNameType!");
+-  if (DNT->getKeyword() != ETK_Typename)
++  if (DNT->getKeyword() != ElaboratedTypeKeyword::Typename)
+     return;
+ 
+   std::string Str = "";
diff --git a/devel/creduce/patches/patch-clang__delta_ReplaceDependentTypedef.cpp b/devel/creduce/patches/patch-clang__delta_ReplaceDependentTypedef.cpp
new file mode 100644
index 000000000000..a735e5153283
--- /dev/null
+++ b/devel/creduce/patches/patch-clang__delta_ReplaceDependentTypedef.cpp
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Build fix for newer llvm.
+
+--- clang_delta/ReplaceDependentTypedef.cpp.orig	2019-05-13 21:17:30.000000000 +0000
++++ clang_delta/ReplaceDependentTypedef.cpp
+@@ -114,7 +114,7 @@ bool ReplaceDependentTypedef::isValidTyp
+   case Type::Elaborated: {
+     const ElaboratedType *ETy = dyn_cast<ElaboratedType>(Ty);
+     ElaboratedTypeKeyword Keyword = ETy->getKeyword();
+-    return ((Keyword == ETK_Typename) || (Keyword == ETK_None));
++    return ((Keyword == ElaboratedTypeKeyword::Typename) || (Keyword == ElaboratedTypeKeyword::None));
+   }
+   
+   default:


Home | Main Index | Thread Index | Old Index