[PATCH] D156244: [clang] Do not crash on use of a variadic overloaded operator

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 25 08:19:02 PDT 2023


Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Just exit instead.
Fixes https://github.com/llvm/llvm-project/issues/42535


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156244

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/overloaded-operator-decl.cpp


Index: clang/test/SemaCXX/overloaded-operator-decl.cpp
===================================================================
--- clang/test/SemaCXX/overloaded-operator-decl.cpp
+++ clang/test/SemaCXX/overloaded-operator-decl.cpp
@@ -58,3 +58,9 @@
     A()(i);
   }
 }
+
+namespace GH42535 {
+class E {};
+void operator+(E, ...) {} // expected-error{{overloaded 'operator+' cannot be variadic}}
+void d() { E() + E(); }
+}
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -13997,6 +13997,10 @@
         std::swap(Args[0], Args[1]);
 
       if (FnDecl) {
+
+        if (FnDecl->isInvalidDecl())
+          return ExprError();
+
         Expr *Base = nullptr;
         // We matched an overloaded operator. Build a call to that
         // operator.
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -685,6 +685,8 @@
   (`#64005 <https://github.com/llvm/llvm-project/issues/64005>_`)
 - Fix crash on nested templated class with template function call.
   (`#61159 <https://github.com/llvm/llvm-project/issues/61159>_`)
+- Fix crash on use of a variadic overloaded operator.
+  (`#42535 <https://github.com/llvm/llvm-project/issues/42535>_`)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156244.543990.patch
Type: text/x-patch
Size: 1456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230725/3887ffaa/attachment.bin>


More information about the cfe-commits mailing list