[clang] [BoundsSafety][Clang][Sema][AST] Introduce CThisExpr for C __counted_by attributes (PR #199241)

Karthik P via cfe-commits cfe-commits at lists.llvm.org
Sun May 31 02:13:05 PDT 2026


================
@@ -4334,6 +4345,7 @@ bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) {
   switch (E1->getStmtClass()) {
     default:
       return false;
+    case CThisExprClass:
     case CXXThisExprClass:
----------------
Caryoake wrote:

An appropriate example could be :-

struct Buffer {
    int size;
    int* data __counted_by(size == size ? size : 0); 
};

Here when Clang sees size  == size, it will implictly resolves both sides to CThis->size.
So to determine if both are identical, it will recurse down to the base,  hit the CThisExprCase, return true (like CXXThisExprClass) and will then recognise both the pseudo pointers refer to the same implicit struct instance.

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


More information about the cfe-commits mailing list