44 lines · c
1// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t2 3#define __must_check __attribute__((warn_unused_result))4 5// Prototypes of the error functions.6void * __must_check ERR_PTR(long error);7long __must_check PTR_ERR(const void *ptr);8int __must_check IS_ERR(const void *ptr);9int __must_check IS_ERR_OR_NULL(const void *ptr);10void * __must_check ERR_CAST(const void *ptr);11int __must_check PTR_ERR_OR_ZERO(const void *ptr);12 13void f(void) {14 ERR_PTR(0);15 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_PTR' is unused16 PTR_ERR((void *)0);17 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR' is unused18 IS_ERR((void *)0);19 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'IS_ERR' is unused20 ERR_CAST((void *)0);21 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_CAST' is unused22out:23 PTR_ERR_OR_ZERO((void *)0);24 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR_OR_ZERO' is unused25}26 27void *f1(void) {28 return ERR_PTR(0);29}30 31long f2(void) {32 if (IS_ERR((void *)0)) {33 return PTR_ERR((void *)0);34 }35 return -1;36}37 38void f3(void) {39 f1();40 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f1' is unused but represents an error value41 f2();42 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f2' is unused but represents an error value43}44