[PATCH] MS ABI: Implement support for throwing a C++ exception

Reid Kleckner rnk at google.com
Wed Mar 4 16:16:21 PST 2015


lgtm


================
Comment at: lib/CodeGen/CGException.cpp:360-363
@@ -379,5 +359,6 @@
 
 // Emits an exception expression into the given location.  This
 // differs from EmitAnyExprToMem only in that, if a final copy-ctor
 // call is required, an exception within that copy ctor causes
 // std::terminate to be invoked.
+void CodeGenFunction::EmitAnyExprToExn(const Expr *e, llvm::Value *addr) {
----------------
Based on reading this comment, it seems like we don't need this on Windows. Move it to ItaniumCXXABI?

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:591
@@ +590,3 @@
+  llvm::StructType *getCatchableTypeArrayType(uint32_t NumEntries) {
+    llvm::SmallString<23> CTATypeName("eh.CatchableTypeArray.");
+    CTATypeName += llvm::utostr(NumEntries);
----------------
Hm, annoying creating such struct types is annoying. Oh well.

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:593-596
@@ +592,6 @@
+    CTATypeName += llvm::utostr(NumEntries);
+    llvm::StructType *&CatchableTypeArrayType =
+        CatchableTypeArrayTypeMap[NumEntries];
+    if (CatchableTypeArrayType)
+      return CatchableTypeArrayType;
+    llvm::Type *CTType =
----------------
Hoist this over building the name string.

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:622
@@ +621,3 @@
+
+  llvm::Constant *getThrowFn() {
+    llvm::Type *Args[] = {CGM.Int8PtrTy, getThrowInfoType()->getPointerTo()};
----------------
Memoize it?

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:3258-3259
@@ +3257,4 @@
+  QualType PointeeType = T;
+  if (T->isPointerType())
+    PointeeType = T->getPointeeType();
+  if (const CXXRecordDecl *RD = PointeeType->getAsCXXRecordDecl()) {
----------------
Can we assert that T is not a reference type here?

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:3287
@@ +3286,3 @@
+  auto *GV = new llvm::GlobalVariable(
+      CGM.getModule(), CTType, /*Constant=*/true, getLinkageForRTTI(T),
+      llvm::ConstantStruct::get(CTType, Fields), MangledName.c_str());
----------------
So presumably this data cannot be dllexported. It's address is insignificant, similar RTTI? Make it unnamed_addr?

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:3288
@@ +3287,3 @@
+      CGM.getModule(), CTType, /*Constant=*/true, getLinkageForRTTI(T),
+      llvm::ConstantStruct::get(CTType, Fields), MangledName.c_str());
+  if (GV->isWeakForLinker())
----------------
Can you do StringRef(MangleName) instead of MangledName.c_str() and see if that works? It's supposed to take a Twine.

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:3314
@@ +3313,3 @@
+  const CXXRecordDecl *MostDerivedClass = nullptr;
+  const bool IsPointer = T->isPointerType();
+  if (IsPointer)
----------------
We don't usually declare local scalars as const.

================
Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:3314
@@ +3313,3 @@
+  const CXXRecordDecl *MostDerivedClass = nullptr;
+  const bool IsPointer = T->isPointerType();
+  if (IsPointer)
----------------
rnk wrote:
> We don't usually declare local scalars as const.
Is it useful to assert that T isn't a reference type?

http://reviews.llvm.org/D8066

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list