From 26bb31123aeb97024c425de8e9688b4c991941fb Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Tue, 16 Aug 2016 00:48:21 +0000 Subject: [PATCH] [CUDA] Fix "declared here" note on deferred wrong-side errors. Previously we weren't deferring these "declared here" notes, which is obviously wrong. llvm-svn: 278767 --- clang/lib/Sema/SemaCUDA.cpp | 15 ++++++++++----- clang/test/SemaCUDA/call-device-fn-from-host.cu | 9 +++++++++ clang/test/SemaCUDA/call-host-fn-from-device.cu | 10 ++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index 4f370d3..6f94e54 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -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; diff --git a/clang/test/SemaCUDA/call-device-fn-from-host.cu b/clang/test/SemaCUDA/call-device-fn-from-host.cu index 0984faa..ab88338 100644 --- a/clang/test/SemaCUDA/call-device-fn-from-host.cu +++ b/clang/test/SemaCUDA/call-device-fn-from-host.cu @@ -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() { diff --git a/clang/test/SemaCUDA/call-host-fn-from-device.cu b/clang/test/SemaCUDA/call-host-fn-from-device.cu index ea7a4cc..4451883 100644 --- a/clang/test/SemaCUDA/call-host-fn-from-device.cu +++ b/clang/test/SemaCUDA/call-host-fn-from-device.cu @@ -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() { -- 2.7.4