================
@@ -99,6 +102,34 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
   else if (ACE)
     CE = ACE;
 
+  bool UseCStr = false;
+  if (CStrDecl) {
+    auto Parents = Result.Context->getParents(*UO);
+
+    if (!Parents.empty()) {
+      if (const auto *VD = Parents[0].get<VarDecl>()) {
+        const QualType VarType = VD->getType();
+        if (VarType->isPointerType()) {
+          const QualType PointeeType = VarType->getPointeeType();
+          UseCStr = PointeeType.isConstQualified();
+        }
+      } else if (const auto *Cast = Parents[0].get<CastExpr>()) {
+        const QualType CastType = Cast->getType();
+        if (CastType->isPointerType()) {
+          const QualType PointeeType = CastType->getPointeeType();
+          UseCStr = PointeeType.isConstQualified();
+        }
+      }
+    }
+
+    if (!UseCStr) {
+      QualType ContainerType = CE->getType();
+      if (ContainerType->isPointerType())
+        ContainerType = ContainerType->getPointeeType();
+      UseCStr = ContainerType.isConstQualified();
+    }
+  }
+
----------------
unterumarmung wrote:

I think this should be a separate `static` function like `shouldUseCStr`. This 
way the code can be simplified to have less deep nesting.

https://github.com/llvm/llvm-project/pull/190590
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to