[clang] Warning for unsafe invocation of span::data (PR #75650)

Ziqing Luo via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 15 14:37:30 PST 2023


================
@@ -2261,6 +2261,21 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler {
         // note_unsafe_buffer_operation doesn't have this mode yet.
         assert(!IsRelatedToDecl && "Not implemented yet!");
         MsgParam = 3;
+      } else if (const auto *ECE = dyn_cast<ExplicitCastExpr>(Operation)) {
+        QualType destType = ECE->getType();
+        const uint64_t dSize = Ctx.getTypeSize(destType.getTypePtr()->getPointeeType());
+        if(const auto *CE =dyn_cast<CXXMemberCallExpr>(ECE->getSubExpr())) {
+
+          if(CE->getRecordDecl()->getQualifiedNameAsString().compare("std::span"))
----------------
ziqingluo-90 wrote:

I'm a tiny bit skeptical that if the qualified name is always `std::span`.  
Maybe we can have a test like this:
```
using namespace std;
void f(span<int> buf) {
   BigTy *p = (BigTy *) buf.data();
}
```

https://github.com/llvm/llvm-project/pull/75650


More information about the cfe-commits mailing list