[clang] 0c2edf2 - [clang][dataflow] Make `Value` and `StorageLocation` non-copyable

Stanislav Gatev via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 09:15:33 PDT 2022


Author: Stanislav Gatev
Date: 2022-06-15T16:14:27Z
New Revision: 0c2edf27a22efb648b36343d49a5dbe72903b549

URL: https://github.com/llvm/llvm-project/commit/0c2edf27a22efb648b36343d49a5dbe72903b549
DIFF: https://github.com/llvm/llvm-project/commit/0c2edf27a22efb648b36343d49a5dbe72903b549.diff

LOG: [clang][dataflow] Make `Value` and `StorageLocation` non-copyable

This makes it harder to misuse APIs that return references by
accidentally copying the results which could happen when assigning the
them to variables declared as `auto`.

Differential Revision: https://reviews.llvm.org/D127865

Reviewed-by: ymandel, xazax.hun

Added: 
    

Modified: 
    clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
    clang/include/clang/Analysis/FlowSensitive/Value.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
index f965486537e61..fdfd03129b81e 100644
--- a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
+++ b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
@@ -31,6 +31,12 @@ class StorageLocation {
 
   StorageLocation(Kind LocKind, QualType Type) : LocKind(LocKind), Type(Type) {}
 
+  // Non-copyable because addresses of storage locations are used as their
+  // identities throughout framework and user code. The framework is responsible
+  // for construction and destruction of storage locations.
+  StorageLocation(const StorageLocation &) = delete;
+  StorageLocation &operator=(const StorageLocation &) = delete;
+
   virtual ~StorageLocation() = default;
 
   Kind getKind() const { return LocKind; }

diff  --git a/clang/include/clang/Analysis/FlowSensitive/Value.h b/clang/include/clang/Analysis/FlowSensitive/Value.h
index 9c93456346b23..70348f8745431 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Value.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Value.h
@@ -47,6 +47,12 @@ class Value {
 
   explicit Value(Kind ValKind) : ValKind(ValKind) {}
 
+  // Non-copyable because addresses of values are used as their identities
+  // throughout framework and user code. The framework is responsible for
+  // construction and destruction of values.
+  Value(const Value &) = delete;
+  Value &operator=(const Value &) = delete;
+
   virtual ~Value() = default;
 
   Kind getKind() const { return ValKind; }


        


More information about the cfe-commits mailing list