forked from OSchip/llvm-project
Do not show macro expansion in strncat warnings, which can be defined as
a builtin. llvm-svn: 149657
This commit is contained in:
parent
60b4f13c11
commit
5069aa33b9
|
@ -2742,12 +2742,22 @@ void Sema::CheckStrncatArguments(const CallExpr *CE,
|
||||||
if (PatternType == 0)
|
if (PatternType == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Generate the diagnostic.
|
||||||
|
SourceLocation SL = LenArg->getLocStart();
|
||||||
|
SourceRange SR = LenArg->getSourceRange();
|
||||||
|
SourceManager &SM = PP.getSourceManager();
|
||||||
|
|
||||||
|
// If the function is defined as a builtin macro, do not show macro expansion.
|
||||||
|
if (SM.isMacroArgExpansion(SL)) {
|
||||||
|
SL = SM.getSpellingLoc(SL);
|
||||||
|
SR = SourceRange(SM.getSpellingLoc(SR.getBegin()),
|
||||||
|
SM.getSpellingLoc(SR.getEnd()));
|
||||||
|
}
|
||||||
|
|
||||||
if (PatternType == 1)
|
if (PatternType == 1)
|
||||||
Diag(DstArg->getLocStart(), diag::warn_strncat_large_size)
|
Diag(SL, diag::warn_strncat_large_size) << SR;
|
||||||
<< LenArg->getSourceRange();
|
|
||||||
else
|
else
|
||||||
Diag(DstArg->getLocStart(), diag::warn_strncat_src_size)
|
Diag(SL, diag::warn_strncat_src_size) << SR;
|
||||||
<< LenArg->getSourceRange();
|
|
||||||
|
|
||||||
// Output a FIXIT hint if the destination is an array (rather than a
|
// Output a FIXIT hint if the destination is an array (rather than a
|
||||||
// pointer to an array). This could be enhanced to handle some
|
// pointer to an array). This could be enhanced to handle some
|
||||||
|
@ -2773,9 +2783,8 @@ void Sema::CheckStrncatArguments(const CallExpr *CE,
|
||||||
DstArg->printPretty(OS, Context, 0, getPrintingPolicy());
|
DstArg->printPretty(OS, Context, 0, getPrintingPolicy());
|
||||||
OS << ") - 1";
|
OS << ") - 1";
|
||||||
|
|
||||||
Diag(LenArg->getLocStart(), diag::note_strncat_wrong_size)
|
Diag(SL, diag::note_strncat_wrong_size)
|
||||||
<< FixItHint::CreateReplacement(LenArg->getSourceRange(),
|
<< FixItHint::CreateReplacement(SR, OS.str());
|
||||||
OS.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===--- CHECK: Return Address of Stack Variable --------------------------===//
|
//===--- CHECK: Return Address of Stack Variable --------------------------===//
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
// RUN: %clang_cc1 -Wstrncat-size -verify -fsyntax-only %s
|
// RUN: %clang_cc1 -Wstrncat-size -verify -fsyntax-only %s
|
||||||
|
// RUN: %clang_cc1 -DUSE_BUILTINS -Wstrncat-size -verify -fsyntax-only %s
|
||||||
|
// RUN: %clang_cc1 -fsyntax-only -Wstrncat-size -fixit -x c %s
|
||||||
|
// RUN: %clang_cc1 -DUSE_BUILTINS -fsyntax-only -Wstrncat-size -fixit -x c %s
|
||||||
|
|
||||||
typedef __SIZE_TYPE__ size_t;
|
typedef __SIZE_TYPE__ size_t;
|
||||||
char *strncat(char *, const char *, size_t);
|
|
||||||
size_t strlen (const char *s);
|
size_t strlen (const char *s);
|
||||||
|
|
||||||
|
#ifdef USE_BUILTINS
|
||||||
|
# define BUILTIN(f) __builtin_ ## f
|
||||||
|
#else
|
||||||
|
# define BUILTIN(f) f
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define strncat BUILTIN(strncat)
|
||||||
|
char *strncat(char *restrict s1, const char *restrict s2, size_t n);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char f1[100];
|
char f1[100];
|
||||||
char f2[100][3];
|
char f2[100][3];
|
||||||
|
|
Loading…
Reference in New Issue