[llvm] BasicAA: update comments in a routine (NFC) (PR #110492)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 04:22:06 PDT 2024


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/110492

The comments in isObjectSmallerThan are outdated, as it is only ever called with the underlying object as the first argument. Update the comments to reflect this.

>From 35fd52be0eb4287fbc69977bac09bf6842087d65 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Mon, 30 Sep 2024 12:15:41 +0100
Subject: [PATCH] BasicAA: update comments in a routine (NFC)

The comments in isObjectSmallerThan are outdated, as it is only ever
called with the underlying object as the first argument. Update the
comments to reflect this.
---
 llvm/lib/Analysis/BasicAliasAnalysis.cpp | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index a00ed7530ebc4c..1c94ccd66436d8 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -117,7 +117,7 @@ static std::optional<TypeSize> getObjectSize(const Value *V,
 }
 
 /// Returns true if we can prove that the object specified by V is smaller than
-/// Size.
+/// Size. The underlying object is expected to be passed as the first argument.
 static bool isObjectSmallerThan(const Value *V, TypeSize Size,
                                 const DataLayout &DL,
                                 const TargetLibraryInfo &TLI,
@@ -134,20 +134,13 @@ static bool isObjectSmallerThan(const Value *V, TypeSize Size,
   //     char *p = (char*)malloc(100)
   //     char *q = p+80;
   //
-  //  In the context of c1 and c2, the "object" pointed by q refers to the
+  // In the context of c1 and c2, the "object" pointed by q refers to the
   // stretch of memory of q[0:19]. So, getObjectSize(q) should return 20.
   //
-  //  However, in the context of c3, the "object" refers to the chunk of memory
-  // being allocated. So, the "object" has 100 bytes, and q points to the middle
-  // the "object". In case q is passed to isObjectSmallerThan() as the 1st
-  // parameter, before the llvm::getObjectSize() is called to get the size of
-  // entire object, we should:
-  //    - either rewind the pointer q to the base-address of the object in
-  //      question (in this case rewind to p), or
-  //    - just give up. It is up to caller to make sure the pointer is pointing
-  //      to the base address the object.
-  //
-  // We go for 2nd option for simplicity.
+  // In the context of c3, the "object" refers to the chunk of memory being
+  // allocated. So, the "object" has 100 bytes, and q points to the middle the
+  // "object". However, getUnderlyingObject() is first called on q to get p, and
+  // p is passed to isObjectSmallerThan() as the 1st parameter.
   if (!isIdentifiedObject(V))
     return false;
 



More information about the llvm-commits mailing list