Skip to content
SimplifyLibCalls.cpp 81.5 KiB
Newer Older
        } else if (Name == "getenv") {
            continue;
          setDoesNotThrow(F);
          setOnlyReadsMemory(F);
        } else if (Name == "gets" ||
                   Name == "getchar") {
        } else if (Name == "getitimer") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 2);
        } else if (Name == "getpwnam") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        if (Name == "ungetc") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 2);
        } else if (Name == "uname" ||
                   Name == "unlink" ||
                   Name == "unsetenv") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "utime" ||
                   Name == "utimes") {
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(1)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 2);
        } else if (Name == "puts" ||
                   Name == "printf" ||
                   Name == "perror") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "pread" ||
                   Name == "pwrite") {
            continue;
          // May throw; these are valid pthread cancellation points.
          setDoesNotCapture(F, 2);
        } else if (Name == "putchar") {
        } else if (Name == "popen") {
              !FTy->getReturnType()->isPointerTy() ||
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(1)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
        } else if (Name == "pclose") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        if (Name == "vscanf") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "vsscanf" ||
                   Name == "vfscanf") {
              !FTy->getParamType(1)->isPointerTy() ||
              !FTy->getParamType(2)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
        } else if (Name == "valloc") {
          if (!FTy->getReturnType()->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
        } else if (Name == "vprintf") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "vfprintf" ||
                   Name == "vsprintf") {
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(1)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
        } else if (Name == "vsnprintf") {
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(2)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 3);
            continue;
          // May throw; "open" is a valid pthread cancellation point.
          setDoesNotCapture(F, 1);
        } else if (Name == "opendir") {
              !FTy->getReturnType()->isPointerTy() ||
              !FTy->getParamType(0)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
        if (Name == "tmpfile") {
          if (!FTy->getReturnType()->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
        } else if (Name == "times") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        if (Name == "htonl" ||
            Name == "htons") {
          setDoesNotThrow(F);
          setDoesNotAccessMemory(F);
        }
        break;
      case 'n':
        if (Name == "ntohl" ||
            Name == "ntohs") {
          setDoesNotThrow(F);
          setDoesNotAccessMemory(F);
        }
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(1)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
        } else if (Name == "lchown") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        }
        break;
      case 'q':
            continue;
          // May throw; places call through function pointer.
          setDoesNotCapture(F, 4);
        }
        break;
        if (Name == "__strdup" ||
            Name == "__strndup") {
              !FTy->getReturnType()->isPointerTy() ||
              !FTy->getParamType(0)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
          setDoesNotCapture(F, 1);
        } else if (Name == "__strtok_r") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 2);
        } else if (Name == "_IO_getc") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "_IO_putc") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 2);
        }
        if (Name == "\1__isoc99_scanf") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "\1stat64" ||
                   Name == "\1lstat64" ||
                   Name == "\1statvfs64" ||
                   Name == "\1__isoc99_sscanf") {
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(1)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
        } else if (Name == "\1fopen64") {
              !FTy->getReturnType()->isPointerTy() ||
              !FTy->getParamType(0)->isPointerTy() ||
              !FTy->getParamType(1)->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
          setDoesNotCapture(F, 1);
          setDoesNotCapture(F, 2);
        } else if (Name == "\1fseeko64" ||
                   Name == "\1ftello64") {
            continue;
          setDoesNotThrow(F);
          setDoesNotCapture(F, 1);
        } else if (Name == "\1tmpfile64") {
          if (!FTy->getReturnType()->isPointerTy())
            continue;
          setDoesNotThrow(F);
          setDoesNotAlias(F, 0);
        } else if (Name == "\1fstat64" ||
                   Name == "\1fstatvfs64") {
        } else if (Name == "\1open64") {
            continue;
          // May throw; "open" is a valid pthread cancellation point.
          setDoesNotCapture(F, 1);

// TODO:
//   Additional cases that we need to add to this file:
//
// cbrt:
//   * cbrt(expN(X))  -> expN(x/3)
//   * cbrt(sqrt(x))  -> pow(x,1/6)
//   * cbrt(sqrt(x))  -> pow(x,1/9)
//
// cos, cosf, cosl:
//   * cos(-x)  -> cos(x)
//
// exp, expf, expl:
//   * exp(log(x))  -> x
//
// log, logf, logl:
//   * log(exp(x))   -> x
//   * log(x**y)     -> y*log(x)
//   * log(exp(y))   -> y*log(e)
//   * log(exp2(y))  -> y*log(2)
//   * log(exp10(y)) -> y*log(10)
//   * log(sqrt(x))  -> 0.5*log(x)
//   * log(pow(x,y)) -> y*log(x)
//
// lround, lroundf, lroundl:
//   * lround(cnst) -> cnst'
//
// pow, powf, powl:
//   * pow(exp(x),y)  -> exp(x*y)
//   * pow(sqrt(x),y) -> pow(x,y*0.5)
//   * pow(pow(x,y),z)-> pow(x,y*z)
//
// round, roundf, roundl:
//   * round(cnst) -> cnst'
//
// signbit:
//   * signbit(cnst) -> cnst'
//   * signbit(nncst) -> 0 (if pstv is a non-negative constant)
//
// sqrt, sqrtf, sqrtl:
//   * sqrt(expN(x))  -> expN(x*0.5)
//   * sqrt(Nroot(x)) -> pow(x,1/(2*N))
//   * sqrt(pow(x,y)) -> pow(|x|,y*0.5)
//
// stpcpy:
//   * stpcpy(str, "literal") ->
//           llvm.memcpy(str,"literal",strlen("literal")+1,1)
//
// tan, tanf, tanl:
//   * tan(atan(x)) -> x
//
// trunc, truncf, truncl:
//   * trunc(cnst) -> cnst'
//
//