brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 868869b Raw
50 lines · c
1// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \2// RUN:   -analyzer-checker=core,deadcode,optin.taint \3// RUN:   -DERRNO_VAR4 5// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \6// RUN:   -analyzer-checker=core,deadcode,optin.taint \7// RUN:   -DERRNO_FUNC8 9// Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.10// The errno value can be defined in multiple ways, test with each one.11#ifdef ERRNO_VAR12#include "Inputs/errno_var.h"13#endif14#ifdef ERRNO_FUNC15#include "Inputs/errno_func.h"16#endif17#include "Inputs/system-header-simulator.h"18 19 20void foo(void);21 22// expected-no-diagnostics23 24// Test errno gets invalidated by a system call.25int testErrnoSystem(void) {26  int i;27  int *p = 0;28  fscanf(stdin, "%d", &i);29  if (errno == 0) {30    fscanf(stdin, "%d", &i); // errno gets invalidated here.31    return 5 / errno; // no-warning32  }33 34  errno = 0;35  fscanf(stdin, "%d", &i); // errno gets invalidated here.36  return 5 / errno; // no-warning37}38 39// Test that errno gets invalidated by internal calls.40int testErrnoInternal(void) {41  int i;42  int *p = 0;43  fscanf(stdin, "%d", &i);44  if (errno == 0) {45    foo(); // errno gets invalidated here.46    return 5 / errno; // no-warning47  }48  return 0;49}50