From ea38e42e96321521cd0583f208c4bcc008bc51b9 Mon Sep 17 00:00:00 2001 From: Shreya Singh <40202207+SHREYASINGH29@users.noreply.github.com> Date: Thu, 24 Jun 2021 17:46:26 +0530 Subject: [PATCH 1/2] Handle null pointer --- lib/Token/Token.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index 48964af..b63e219 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -12,6 +12,8 @@ void Token::set(llvm::Value *Val, unsigned int Kind, std::string Index, this->IsGlobal = Global; if (!Func) this->IsGlobal = true; + if(llvm::isa(Val)) + this->name = "NULL"; } void Token::set(llvm::Type *Ty, unsigned int Kind, std::string Index) { @@ -161,6 +163,8 @@ std::ostream &operator<<(std::ostream &OS, const Token &A) { /// function etc llvm::StringRef Token::getName() const { if (this->Kind == 0) { + if(this->name != "") + return this->name; return this->Val->getName(); } else if (this->Kind == 2) { return this->Arg->getName(); @@ -234,6 +238,11 @@ bool Token::isValPointerType() const { return false; } +/// isNullPointer - Return true if token is a nullptr +bool Token::isNullPointer() const { + return this->name == "NULL"; +} + /// getHash - Calculates the hash for alias to avoid multiple enteries of same /// alias std::string Token::getHash() const { From 754ace8f7253e2794a3fad7c3a6bb94a134541b4 Mon Sep 17 00:00:00 2001 From: Shreya Singh <40202207+SHREYASINGH29@users.noreply.github.com> Date: Thu, 24 Jun 2021 17:50:24 +0530 Subject: [PATCH 2/2] Declare null pointer check --- include/Token/Token.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/Token/Token.h b/include/Token/Token.h index 9dea750..af18552 100644 --- a/include/Token/Token.h +++ b/include/Token/Token.h @@ -10,6 +10,7 @@ #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/IR/Constants.h" namespace spatial { @@ -68,6 +69,7 @@ class Token { bool isValPointerType() const; std::string getHash() const; bool isPointerType() const; + bool isNullPointer() const; bool operator<(const Token &TheToken) const; bool operator==(const Token &TheToken) const;