[llvm-dev] How to read String value of GlobalVariable?

Zhang via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 20 23:26:36 PDT 2018


```
if(GVPath->hasInitializer()){
  if(ConstantDataArray* CDA=dyn_cast<ConstantDataArray>(GVPath->getInitializer())){
  StringRef str=CDA->getAsString();
  }
}
```
 
 
------------------ Original ------------------
From:  "Mahesh Attarde via llvm-dev"<llvm-dev at lists.llvm.org>;
Date:  Wed, Mar 21, 2018 06:52 AM
To:  "llvm-dev"<llvm-dev at lists.llvm.org>; 

Subject:  [llvm-dev] How to read String value of GlobalVariable?

 
Hi 

 I have IR Code like

...

@path = private constant [6xi8] c"abcde\00"
...




--- Code from Pass --- 

GlobalVariable * GVPath = ....  // contains @path


I want to convert "abcde" to StringRef. Can you  help me with GlobalVariable API?  

GlobalVariable::getInitializer() --> Constant*  // How to get exact value äbcde from here?



~mahesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180321/18aa5e2e/attachment.html>


More information about the llvm-dev mailing list