[clang] 1c85a2e - isBuiltinFunc() uses StringRef instead of const char*
Guillaume Chatelet via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 29 09:37:17 PDT 2019
Author: Guillaume Chatelet
Date: 2019-10-29T17:36:55+01:00
New Revision: 1c85a2e8dc7e76761d301f9a35374e0aafc757ec
URL: https://github.com/llvm/llvm-project/commit/1c85a2e8dc7e76761d301f9a35374e0aafc757ec
DIFF: https://github.com/llvm/llvm-project/commit/1c85a2e8dc7e76761d301f9a35374e0aafc757ec.diff
LOG: isBuiltinFunc() uses StringRef instead of const char*
Summary: This prevents a bug when passing nullptr, StringRef ctor would call strlen(nullptr).
Reviewers: vlad.tsyrklevich
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69569
Added:
Modified:
clang/include/clang/Basic/Builtins.h
clang/lib/Basic/Builtins.cpp
clang/lib/Sema/SemaDeclAttr.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Builtins.h b/clang/include/clang/Basic/Builtins.h
index fed0dae20193..af07d4241438 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -224,7 +224,7 @@ class Context {
/// Returns true if this is a libc/libm function without the '__builtin_'
/// prefix.
- static bool isBuiltinFunc(const char *Name);
+ static bool isBuiltinFunc(llvm::StringRef Name);
/// Returns true if this is a builtin that can be redeclared. Returns true
/// for non-builtins.
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index d23c280d4758..0cd89df41b67 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -47,8 +47,7 @@ void Builtin::Context::InitializeTarget(const TargetInfo &Target,
AuxTSRecords = AuxTarget->getTargetBuiltins();
}
-bool Builtin::Context::isBuiltinFunc(const char *Name) {
- StringRef FuncName(Name);
+bool Builtin::Context::isBuiltinFunc(llvm::StringRef FuncName) {
for (unsigned i = Builtin::NotBuiltin + 1; i != Builtin::FirstTSBuiltin; ++i)
if (FuncName.equals(BuiltinInfo[i].Name))
return strchr(BuiltinInfo[i].Attributes, 'f') != nullptr;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 99eb23c3fe61..7f68d2014916 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1096,7 +1096,7 @@ static void handleNoBuiltinAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!S.checkStringLiteralArgumentAttr(AL, I, BuiltinName, &LiteralLoc))
return;
- if (Builtin::Context::isBuiltinFunc(BuiltinName.data()))
+ if (Builtin::Context::isBuiltinFunc(BuiltinName))
AddBuiltinName(BuiltinName);
else
S.Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name)
More information about the cfe-commits
mailing list