]> granicus.if.org Git - clang/commitdiff
[CUDA] Fix "declared here" note on deferred wrong-side errors.
authorJustin Lebar <jlebar@google.com>
Tue, 16 Aug 2016 00:48:21 +0000 (00:48 +0000)
committerJustin Lebar <jlebar@google.com>
Tue, 16 Aug 2016 00:48:21 +0000 (00:48 +0000)
Previously we weren't deferring these "declared here" notes, which is
obviously wrong.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCUDA.cpp
test/SemaCUDA/call-device-fn-from-host.cu
test/SemaCUDA/call-host-fn-from-device.cu

index 4f370d389c608cfab16e24b4888b83ac88bb49b5..6f94e54a0cc2c94e491f098a3e8ed45bb9b643b2 100644 (file)
@@ -499,11 +499,16 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) {
   if (Pref == Sema::CFP_WrongSide) {
     // We have to do this odd dance to create our PartialDiagnostic because we
     // want its storage to be allocated with operator new, not in an arena.
-    PartialDiagnostic PD{PartialDiagnostic::NullDiagnostic()};
-    PD.Reset(diag::err_ref_bad_target);
-    PD << IdentifyCUDATarget(Callee) << Callee << IdentifyCUDATarget(Caller);
-    Caller->addDeferredDiag({Loc, std::move(PD)});
-    Diag(Callee->getLocation(), diag::note_previous_decl) << Callee;
+    PartialDiagnostic ErrPD{PartialDiagnostic::NullDiagnostic()};
+    ErrPD.Reset(diag::err_ref_bad_target);
+    ErrPD << IdentifyCUDATarget(Callee) << Callee << IdentifyCUDATarget(Caller);
+    Caller->addDeferredDiag({Loc, std::move(ErrPD)});
+
+    PartialDiagnostic NotePD{PartialDiagnostic::NullDiagnostic()};
+    NotePD.Reset(diag::note_previous_decl);
+    NotePD << Callee;
+    Caller->addDeferredDiag({Callee->getLocation(), std::move(NotePD)});
+
     // This is not immediately an error, so return true.  The deferred errors
     // will be emitted if and when Caller is codegen'ed.
     return true;
index 0984faa290f81e7997ec9fc24449975f16ef1ffe..ab88338b80d25bde9ff63da6f41d3c67127152ac 100644 (file)
@@ -6,10 +6,18 @@
 #include "Inputs/cuda.h"
 
 __device__ void device_fn() {}
+// expected-note@-1 {{'device_fn' declared here}}
+// expected-note@-2 {{'device_fn' declared here}}
+// expected-note@-3 {{'device_fn' declared here}}
+// expected-note@-4 {{'device_fn' declared here}}
+// expected-note@-5 {{'device_fn' declared here}}
 
 struct S {
   __device__ S() {}
+  // expected-note@-1 {{'S' declared here}}
+  // expected-note@-2 {{'S' declared here}}
   __device__ ~S() { device_fn(); }
+  // expected-note@-1 {{'~S' declared here}}
   int x;
 };
 
@@ -24,6 +32,7 @@ struct T {
   __host__ __device__ void hd3();
 
   __device__ void d() {}
+  // expected-note@-1 {{'d' declared here}}
 };
 
 __host__ __device__ void T::hd3() {
index ea7a4cce8d2b6e5ab9642daa9369fbf95730f582..445188372f5ee63332553bd3e9f6f542c450e1cf 100644 (file)
@@ -6,10 +6,19 @@
 #include "Inputs/cuda.h"
 
 extern "C" void host_fn() {}
+// expected-note@-1 {{'host_fn' declared here}}
+// expected-note@-2 {{'host_fn' declared here}}
+// expected-note@-3 {{'host_fn' declared here}}
+// expected-note@-4 {{'host_fn' declared here}}
+// expected-note@-5 {{'host_fn' declared here}}
+// expected-note@-6 {{'host_fn' declared here}}
 
 struct S {
   S() {}
+  // expected-note@-1 {{'S' declared here}}
+  // expected-note@-2 {{'S' declared here}}
   ~S() { host_fn(); }
+  // expected-note@-1 {{'~S' declared here}}
   int x;
 };
 
@@ -24,6 +33,7 @@ struct T {
   __host__ __device__ void hd3();
 
   void h() {}
+  // expected-note@-1 {{'h' declared here}}
 };
 
 __host__ __device__ void T::hd3() {