================ @@ -0,0 +1,194 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -verify %s +// These are in a separate file because errors (e.g. incompatible attributes) currently prevent +// the AnalysisBasedWarnings pass from running at all. + +// This diagnostic is re-enabled and exercised in isolation later in this file. +#pragma clang diagnostic ignored "-Wperf-constraint-implies-noexcept" + +// --- CONSTRAINTS --- + +void nl1() [[clang::nonblocking]] +{ + auto* pInt = new int; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}} +} + +void nl2() [[clang::nonblocking]] +{ + static int global; // expected-warning {{'nonblocking' function must not have static locals}} +} + +void nl3() [[clang::nonblocking]] +{ + try { + throw 42; // expected-warning {{'nonblocking' function must not throw or catch exceptions}} + } + catch (...) { // expected-warning {{'nonblocking' function must not throw or catch exceptions}} + } +} + +void nl4_inline() {} +void nl4_not_inline(); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}} + +void nl4() [[clang::nonblocking]] +{ + nl4_inline(); // OK + nl4_not_inline(); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}} +} + + +struct HasVirtual { + virtual void unsafe(); // expected-note {{virtual method cannot be inferred 'nonblocking'}} +}; + +void nl5() [[clang::nonblocking]] +{ + HasVirtual hv; + hv.unsafe(); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function}} +} + +void nl6_unsafe(); // expected-note {{function cannot be inferred 'nonblocking' because it has no definition in this translation unit}} +void nl6_transitively_unsafe() +{ + nl6_unsafe(); // expected-note {{function cannot be inferred 'nonblocking' because it calls non-'nonblocking' function}} ---------------- dougsonos wrote:
Yeah, it used to do that, but in the earlier PR I was convinced that this was inconsistent with other diagnostics. https://github.com/llvm/llvm-project/pull/84983/files/eb204dff79817667c65f09bbd38ece245f50b99e#r1523330556 In testing, I found that the diagnostics as is were quite usable in an IDE, since the warning points right to the caller, and in almost all cases there is a note pointing to the callee. Also, there's a question of how to name a lambda. https://github.com/llvm/llvm-project/pull/99656 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits