Check the canonical parameter type with getAs<>() in a static checker

This will prevent breakage when I introduce the DecayedType sugar node.

llvm-svn: 184755
This commit is contained in:
Reid Kleckner 2013-06-24 16:56:16 +00:00
parent 86247b6e27
commit 7f62b95480
2 changed files with 7 additions and 6 deletions

View File

@ -307,7 +307,7 @@ void WalkAST::checkCall_gets(const CallExpr *CE, const FunctionDecl *FD) {
return;
// Is the argument a 'char*'?
const PointerType *PT = dyn_cast<PointerType>(FPT->getArgType(0));
const PointerType *PT = FPT->getArgType(0)->getAs<PointerType>();
if (!PT)
return;
@ -349,7 +349,7 @@ void WalkAST::checkCall_getpw(const CallExpr *CE, const FunctionDecl *FD) {
return;
// Verify the second argument type is char*.
const PointerType *PT = dyn_cast<PointerType>(FPT->getArgType(1));
const PointerType *PT = FPT->getArgType(1)->getAs<PointerType>();
if (!PT)
return;
@ -391,7 +391,7 @@ void WalkAST::checkCall_mktemp(const CallExpr *CE, const FunctionDecl *FD) {
return;
// Verify that the argument is Pointer Type.
const PointerType *PT = dyn_cast<PointerType>(FPT->getArgType(0));
const PointerType *PT = FPT->getArgType(0)->getAs<PointerType>();
if (!PT)
return;
@ -568,7 +568,7 @@ bool WalkAST::checkCall_strCommon(const CallExpr *CE, const FunctionDecl *FD) {
// Verify the type for both arguments.
for (int i = 0; i < 2; i++) {
// Verify that the arguments are pointers.
const PointerType *PT = dyn_cast<PointerType>(FPT->getArgType(i));
const PointerType *PT = FPT->getArgType(i)->getAs<PointerType>();
if (!PT)
return false;
@ -598,7 +598,7 @@ void WalkAST::checkCall_rand(const CallExpr *CE, const FunctionDecl *FD) {
if (FTP->getNumArgs() == 1) {
// Is the argument an 'unsigned short *'?
// (Actually any integer type is allowed.)
const PointerType *PT = dyn_cast<PointerType>(FTP->getArgType(0));
const PointerType *PT = FTP->getArgType(0)->getAs<PointerType>();
if (!PT)
return;

View File

@ -82,10 +82,11 @@ void test_setuid()
}
// <rdar://problem/6337100> CWE-338: Use of cryptographically weak prng
typedef unsigned short *ushort_ptr_t; // Test that sugar doesn't confuse the warning.
int rand(void);
double drand48(void);
double erand48(unsigned short[3]);
long jrand48(unsigned short[3]);
long jrand48(ushort_ptr_t);
void lcong48(unsigned short[7]);
long lrand48(void);
long mrand48(void);