Hello
Attached you can find my first clang patch which should implement
"cond ? throw 1 : val".
Without this patch I get: "cannot compile this l-value expression yet"
As this is my first time looking under the hood of clang I'm not sure if
this is the right approach. I'm Looking forward to your feedback.
- Marius Wachtler
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp (revision 210556)
+++ lib/CodeGen/CGExpr.cpp (working copy)
@@ -874,7 +874,16 @@
case Expr::MaterializeTemporaryExprClass:
return EmitMaterializeTemporaryExpr(cast<MaterializeTemporaryExpr>(E));
+
+ case Expr::CXXThrowExprClass: {
+ const auto* throwExpr = cast<CXXThrowExpr>(E);
+ EmitCXXThrowExpr(throwExpr);
+ const QualType subExprType = throwExpr->getSubExpr()->getType();
+ llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(subExprType));
+ return MakeAddrLValue(llvm::UndefValue::get(Ty), subExprType);
}
+
+ }
}
/// Given an object of the given canonical type, can we safely copy a
Index: test/CodeGenCXX/throw-expressions.cpp
===================================================================
--- test/CodeGenCXX/throw-expressions.cpp (revision 210556)
+++ test/CodeGenCXX/throw-expressions.cpp (working copy)
@@ -80,3 +80,19 @@
// CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN6DR15601AD1Ev {{.*}} @_ZGRN6DR15601rE
// CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
}
+
+void test7(bool cond) {
+ cond ? throw 1 : val;
+}
+// CHECK-LABEL: define void @_Z5test7b(
+// CHECK: br i1
+//
+// x.true:
+// CHECK: call void @__cxa_throw(
+// CHECK-NEXT: unreachable
+//
+// x.false:
+// CHECK: br label
+//
+// end:
+// CHECK: ret void
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits