https://github.com/LocalPiper updated 
https://github.com/llvm/llvm-project/pull/230692

>From fe24680838eda8d05fca2550ad576ed552a60c3b Mon Sep 17 00:00:00 2001
From: LocalPiper <[email protected]>
Date: Sat, 10 Oct 2026 01:22:06 +0300
Subject: [PATCH 1/2] [clang][AST] Add public wrapper getOpcodeStr to
 UnaryOperator

---
 clang/include/clang/AST/Expr.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 6863d9c2633df..7187db2306f2d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2399,6 +2399,8 @@ class UnaryOperator final
   /// corresponds to, e.g. "sizeof" or "[pre]++"
   static StringRef getOpcodeStr(Opcode Op);
 
+  StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
+
   /// Retrieve the unary opcode that corresponds to the given
   /// overloaded operator.
   static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);

>From 896346d4fecc410ffe1751643a5538547c82d2da Mon Sep 17 00:00:00 2001
From: LocalPiper <[email protected]>
Date: Sat, 10 Oct 2026 13:13:38 +0300
Subject: [PATCH 2/2] [clang][AST] Add public member getOpcodeStr usage per
 review feedback

---
 clang-tools-extra/clangd/DumpAST.cpp                          | 2 +-
 clang/include/clang/ASTMatchers/ASTMatchersInternal.h         | 4 ++--
 clang/lib/Analysis/UnsafeBufferUsage.cpp                      | 2 +-
 .../Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp       | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clangd/DumpAST.cpp 
b/clang-tools-extra/clangd/DumpAST.cpp
index faa18fb7baa46..61a1245f5a859 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -237,7 +237,7 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> 
{
     if (const auto *BO = dyn_cast<BinaryOperator>(S))
       return BO->getOpcodeStr().str();
     if (const auto *UO = dyn_cast<UnaryOperator>(S))
-      return UnaryOperator::getOpcodeStr(UO->getOpcode()).str();
+      return UO->getOpcodeStr().str();
     if (const auto *CCO = dyn_cast<CXXConstructExpr>(S))
       return CCO->getConstructor()->getNameAsString();
     if (const auto *CTE = dyn_cast<CXXThisExpr>(S)) {
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index fcf5cd2faf969..859fe85e98d75 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2254,7 +2254,7 @@ std::optional<SourceLocation> 
getExpansionLocOfMacro(StringRef MacroName,
                                                      const ASTContext 
&Context);
 
 inline std::optional<StringRef> getOpName(const UnaryOperator &Node) {
-  return Node.getOpcodeStr(Node.getOpcode());
+  return Node.getOpcodeStr();
 }
 inline std::optional<StringRef> getOpName(const BinaryOperator &Node) {
   return Node.getOpcodeStr();
@@ -2297,7 +2297,7 @@ class HasAnyOperatorNameMatcher : public 
SingleNodeMatcherInterface<T> {
 
 private:
   static std::optional<StringRef> getOpName(const UnaryOperator &Node) {
-    return Node.getOpcodeStr(Node.getOpcode());
+    return Node.getOpcodeStr();
   }
   static std::optional<StringRef> getOpName(const BinaryOperator &Node) {
     return Node.getOpcodeStr();
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 09f610358ca65..99601fdca6d82 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -53,7 +53,7 @@ class StmtDebugPrinter
   }
 
   std::string VisitUnaryOperator(const UnaryOperator *UO) {
-    return "UnaryOperator(" + UO->getOpcodeStr(UO->getOpcode()).str() + ")";
+    return "UnaryOperator(" + UO->getOpcodeStr().str() + ")";
   }
 
   std::string VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
diff --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp
index 481559ed08efd..ce3c867228bd9 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp
@@ -29,7 +29,7 @@ class RecordingVisitor : public 
CRTPTestVisitor<RecordingVisitor> {
   bool shouldTraversePostOrder() const { return VisitPostOrder; }
 
   bool VisitUnaryOperator(UnaryOperator *Op) {
-    VisitedNodes.push_back(std::string(Op->getOpcodeStr(Op->getOpcode())));
+    VisitedNodes.push_back(std::string(Op->getOpcodeStr()));
     return true;
   }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to