Author: Reid Kleckner
Date: 2019-11-07T14:52:04-08:00
New Revision: 7177ce978e8f8e5409cec90bad07df92441656e3

URL: 
https://github.com/llvm/llvm-project/commit/7177ce978e8f8e5409cec90bad07df92441656e3
DIFF: 
https://github.com/llvm/llvm-project/commit/7177ce978e8f8e5409cec90bad07df92441656e3.diff

LOG: [SEH] Defer checking filter expression types until instantiaton

While here, wordsmith the error a bit. Now clang says:
  error: filter expression has non-integral type 'Foo'

Fixes PR43779

Reviewers: amccarth

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

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Sema/SemaStmt.cpp
    clang/test/Sema/__try.c
    clang/test/SemaCXX/exceptions-seh.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1aff4688de5d..88d73dc89b55 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8935,7 +8935,7 @@ def err_unknown_any_function : Error<
   "function %0 with unknown type must be given a function type">;
 
 def err_filter_expression_integral : Error<
-  "filter expression type should be an integral value not %0">;
+  "filter expression has non-integral type %0">;
 
 def err_non_asm_stmt_in_naked_function : Error<
   "non-ASM statement in naked function is not supported">;

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 6c680f29da4f..9680720f549e 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -4184,19 +4184,16 @@ StmtResult Sema::ActOnSEHTryBlock(bool IsCXXTry, 
SourceLocation TryLoc,
   return SEHTryStmt::Create(Context, IsCXXTry, TryLoc, TryBlock, Handler);
 }
 
-StmtResult
-Sema::ActOnSEHExceptBlock(SourceLocation Loc,
-                          Expr *FilterExpr,
-                          Stmt *Block) {
+StmtResult Sema::ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr,
+                                     Stmt *Block) {
   assert(FilterExpr && Block);
-
-  if(!FilterExpr->getType()->isIntegerType()) {
-    return StmtError(Diag(FilterExpr->getExprLoc(),
-                     diag::err_filter_expression_integral)
-                     << FilterExpr->getType());
+  QualType FTy = FilterExpr->getType();
+  if (!FTy->isIntegerType() && !FTy->isDependentType()) {
+    return StmtError(
+        Diag(FilterExpr->getExprLoc(), diag::err_filter_expression_integral)
+        << FTy);
   }
-
-  return SEHExceptStmt::Create(Context,Loc,FilterExpr,Block);
+  return SEHExceptStmt::Create(Context, Loc, FilterExpr, Block);
 }
 
 void Sema::ActOnStartSEHFinallyBlock() {

diff  --git a/clang/test/Sema/__try.c b/clang/test/Sema/__try.c
index cfb47e61d4ca..f7c5c97da104 100644
--- a/clang/test/Sema/__try.c
+++ b/clang/test/Sema/__try.c
@@ -111,7 +111,7 @@ void TEST() {
   __try {
 
   }
-  __except ( NotFilterExpression() ) { // expected-error{{filter expression 
type should be an integral value not 'const char *'}}
+  __except ( NotFilterExpression() ) { // expected-error{{filter expression 
has non-integral type 'const char *'}}
 
   }
 }

diff  --git a/clang/test/SemaCXX/exceptions-seh.cpp 
b/clang/test/SemaCXX/exceptions-seh.cpp
index 7375ec9bf816..1d8cc4917e98 100644
--- a/clang/test/SemaCXX/exceptions-seh.cpp
+++ b/clang/test/SemaCXX/exceptions-seh.cpp
@@ -113,3 +113,17 @@ void (^use_cxx_in_global_block)() = ^{
   } catch(int) {
   }
 };
+
+template <class T> void dependent_filter() {
+  __try {
+    might_crash();
+  } __except (T()) { // expected-error {{filter expression has non-integral 
type 'NotInteger'}}
+  }
+}
+
+struct NotInteger { int x; };
+
+void instantiate_dependent_filter() {
+  dependent_filter<int>();
+  dependent_filter<NotInteger>(); // expected-note {{requested here}}
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to