[llvm] r370309 - [COFF] Fix error handling in ResourceSectionRef

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 01:59:41 PDT 2019


Author: mstorsjo
Date: Thu Aug 29 01:59:41 2019
New Revision: 370309

URL: http://llvm.org/viewvc/llvm-project?rev=370309&view=rev
Log:
[COFF] Fix error handling in ResourceSectionRef

Previously, the expression (Reader.readFoo()) was expanded twice,
triggering asserts as one of the Error types ends up not checked
(and as it was expanded twice, the method would end up called twice
if it failed first).

Differential Revision: https://reviews.llvm.org/D66817

Modified:
    llvm/trunk/lib/Object/COFFObjectFile.cpp

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=370309&r1=370308&r2=370309&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Aug 29 01:59:41 2019
@@ -1662,9 +1662,12 @@ std::error_code BaseRelocRef::getRVA(uin
   return std::error_code();
 }
 
-#define RETURN_IF_ERROR(E)                                                     \
-  if (E)                                                                       \
-    return E;
+#define RETURN_IF_ERROR(Expr)                                                  \
+  do {                                                                         \
+    Error E = (Expr);                                                          \
+    if (E)                                                                     \
+      return std::move(E);                                                     \
+  } while (0)
 
 Expected<ArrayRef<UTF16>>
 ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {




More information about the llvm-commits mailing list