diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1129,6 +1129,9 @@ // libc and the CRT to be skipped. def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">; +// A warning group for specific gotchas surrounding use of interrupt handlers on ARM +def ARMInterruptSafety : DiagGroup<"arm-interrupt-safety">; + // A warning group for things that will change semantics in the future. def FutureCompat : DiagGroup<"future-compat">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -285,7 +285,7 @@ "interrupt service routine cannot be called directly">; def warn_arm_interrupt_calling_convention : Warning< "call to function without interrupt attribute could clobber interruptee's VFP registers">, - InGroup; + InGroup; def warn_interrupt_attribute_invalid : Warning< "%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to " "functions that have %select{no parameters|a 'void' return type}1">, diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5925,12 +5925,20 @@ // so there's some risk when calling out to non-interrupt handler functions // that the callee might not preserve them. This is easy to diagnose here, // but can be very challenging to debug. - if (auto *Caller = getCurFunctionDecl()) - if (Caller->hasAttr()) { - bool VFP = Context.getTargetInfo().hasFeature("vfp"); - if (VFP && (!FDecl || !FDecl->hasAttr())) - Diag(Fn->getExprLoc(), diag::warn_arm_interrupt_calling_convention); - } + if (Context.getTargetInfo().hasFeature("vfp")) + if (auto *Caller = getCurFunctionDecl()) + if (Caller->hasAttr()) { + const Decl *CalleeDecl = FDecl; + if (const auto *UO = dyn_cast(Fn->IgnoreParens())) { + if (const auto *TT = + dyn_cast(UO->getSubExpr()->getType())) + CalleeDecl = TT->getDecl(); + } else if (const auto *TT = Fn->getType()->getAs()) { + CalleeDecl = TT->getDecl(); + } + if (!CalleeDecl || !CalleeDecl->hasAttr()) + Diag(Fn->getExprLoc(), diag::warn_arm_interrupt_calling_convention); + } // Promote the function operand. // We special-case function promotion here because we only allow promoting diff --git a/clang/test/Sema/arm-interrupt-attr.c b/clang/test/Sema/arm-interrupt-attr.c --- a/clang/test/Sema/arm-interrupt-attr.c +++ b/clang/test/Sema/arm-interrupt-attr.c @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 %s -triple arm-apple-darwin -target-feature +vfp2 -verify -fsyntax-only -// RUN: %clang_cc1 %s -triple thumb-apple-darwin -target-feature +vfp3 -verify -fsyntax-only -// RUN: %clang_cc1 %s -triple armeb-none-eabi -target-feature +vfp4 -verify -fsyntax-only -// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -target-feature +neon -verify -fsyntax-only -// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -target-feature +neon -target-feature +soft-float -DSOFT -verify -fsyntax-only +// RUN: %clang_cc1 %s -Warm-interrupt-safety -triple arm-apple-darwin -target-feature +vfp2 -verify -fsyntax-only +// RUN: %clang_cc1 %s -Warm-interrupt-safety -triple thumb-apple-darwin -target-feature +vfp3 -verify -fsyntax-only +// RUN: %clang_cc1 %s -Warm-interrupt-safety -triple armeb-none-eabi -target-feature +vfp4 -verify -fsyntax-only +// RUN: %clang_cc1 %s -Warm-interrupt-safety -triple thumbeb-none-eabi -target-feature +neon -verify -fsyntax-only +// RUN: %clang_cc1 %s -Warm-interrupt-safety -triple thumbeb-none-eabi -target-feature +neon -target-feature +soft-float -DSOFT -verify -fsyntax-only __attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' attribute requires a string}} __attribute__((interrupt("irq"))) void foo1() {} // expected-warning {{'interrupt' attribute argument not supported: irq}} @@ -26,24 +26,36 @@ callee2(); } -#ifndef SOFT __attribute__((interrupt("IRQ"))) void caller2() { +#ifndef SOFT callee1(); // expected-warning {{call to function without interrupt attribute could clobber interruptee's VFP registers}} - callee2(); -} - -void (*callee3)(); -__attribute__((interrupt("IRQ"))) void caller3() { - callee3(); // expected-warning {{call to function without interrupt attribute could clobber interruptee's VFP registers}} -} #else -__attribute__((interrupt("IRQ"))) void caller2() { callee1(); +#endif callee2(); } void (*callee3)(); __attribute__((interrupt("IRQ"))) void caller3() { +#ifndef SOFT + callee3(); // expected-warning {{call to function without interrupt attribute could clobber interruptee's VFP registers}} +#else callee3(); +#endif } + +void __attribute__((interrupt("IRQ"))) bugzilla35527() { + typedef void __attribute__((interrupt("IRQ"))) (*interrupt_callback_t)(int i, void *ctx); + interrupt_callback_t interrupt_callee; + interrupt_callee(42, 0); + (interrupt_callee)(42, 0); + (*interrupt_callee)(42, 0); + + typedef void (*callback_t)(int i, void *ctx); + callback_t callee; +#ifndef SOFT + callee(37, 0); // expected-warning {{call to function without interrupt attribute could clobber interruptee's VFP registers}} +#else + callee(37, 0); #endif +}