Skip to content
SimplifyLibCalls.cpp 76.5 KiB
Newer Older
          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)
//
// puts:
//   * puts("") -> putchar("\n")
//
// 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)
// strrchr:
//   * strrchr(s,c) -> reverse_offset_of_in(c,s)
//      (if c is a constant integer and s is a constant string)
//   * strrchr(s1,0) -> strchr(s1,0)
//
// strpbrk:
//   * strpbrk(s,a) -> offset_in_for(s,a)
//      (if s and a are both constant strings)
//   * strpbrk(s,"") -> 0
//   * strpbrk(s,a) -> strchr(s,a[0]) (if a is constant string of length 1)
//
// strspn, strcspn:
//   * strspn(s,a)   -> const_int (if both args are constant)
//   * strspn("",a)  -> 0
//   * strspn(s,"")  -> 0
//   * strcspn(s,a)  -> const_int (if both args are constant)
//   * strcspn("",a) -> 0
//   * strcspn(s,"") -> strlen(a)
//
// tan, tanf, tanl:
//   * tan(atan(x)) -> x
//
// trunc, truncf, truncl:
//   * trunc(cnst) -> cnst'
//
//