summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-06-03 10:58:26 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-06-03 10:58:26 +0200
commit643b70006fd5f6762561696421808f20d4e1e86f (patch)
treee770962bd4830b9b41abf5446f5674f67c164048 /compilerplugins
parent9cf0ac710a6ace0a833fa193c7e18c4a7405bc42 (diff)
Teach loplugin:stringconstant about RTL_CONSTASCII_STRINGPARAM
Change-Id: I8ff0e104aad045f3835dc8facc760a8339b1d088
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringconstant.cxx14
-rw-r--r--compilerplugins/clang/typecheck.cxx10
-rw-r--r--compilerplugins/clang/typecheck.hxx2
3 files changed, 26 insertions, 0 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 456413c6eb99..c68d58f9b6b0 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -821,6 +821,20 @@ bool StringConstant::isStringConstant(
assert(embeddedNuls != nullptr);
assert(terminatingNul != nullptr);
QualType t = expr->getType();
+ // Look inside RTL_CONSTASCII_STRINGPARAM:
+ if (loplugin::TypeCheck(t).Pointer().Const().Char()) {
+ auto e2 = dyn_cast<UnaryOperator>(expr);
+ if (e2 == nullptr || e2->getOpcode() != UO_AddrOf) {
+ return false;
+ }
+ auto e3 = dyn_cast<ArraySubscriptExpr>(
+ e2->getSubExpr()->IgnoreParenImpCasts());
+ if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) {
+ return false;
+ }
+ expr = e3->getBase()->IgnoreParenImpCasts();
+ t = expr->getType();
+ }
if (!(t->isConstantArrayType() && t.isConstQualified()
&& (loplugin::TypeCheck(t->getAsArrayTypeUnsafe()->getElementType())
.Char())))
diff --git a/compilerplugins/clang/typecheck.cxx b/compilerplugins/clang/typecheck.cxx
index e185643ec32e..800a2d295bc7 100644
--- a/compilerplugins/clang/typecheck.cxx
+++ b/compilerplugins/clang/typecheck.cxx
@@ -39,6 +39,16 @@ TypeCheck TypeCheck::LvalueReference() const {
return TypeCheck();
}
+TypeCheck TypeCheck::Pointer() const {
+ if (!type_.isNull()) {
+ auto const t = type_->getAs<clang::PointerType>();
+ if (t != nullptr) {
+ return TypeCheck(t->getPointeeType());
+ }
+ }
+ return TypeCheck();
+}
+
TypeCheck TypeCheck::NotSubstTemplateTypeParmType() const {
return
(!type_.isNull()
diff --git a/compilerplugins/clang/typecheck.hxx b/compilerplugins/clang/typecheck.hxx
index 70e3d8c9c265..c49adccae3c3 100644
--- a/compilerplugins/clang/typecheck.hxx
+++ b/compilerplugins/clang/typecheck.hxx
@@ -31,6 +31,8 @@ public:
TerminalCheck Char() const;
+ TypeCheck Pointer() const;
+
TypeCheck LvalueReference() const;
template<std::size_t N> inline NamespaceCheck Class(char const (& id)[N])