Commits

gnarf committed 3cca961

fixed treatment of pointer values in PHI-resolution (use pointerTo for AllocaInsts)

Comments (0)

Files changed (2)

lib/axtor/backend/generic/GenericCWriter.cpp

 	 	const VariableDesc * srcDesc = locals.lookUp(val);
 	 	std::string srcText;
 
-	 	if (srcDesc) {
-	 		srcText = srcDesc->name;
-	 	} else if (llvm::isa<llvm::GetElementPtrInst>(val)) {
+	 	// Allocas need to be dereferenced explicitely
+	 	if (val->getType()->isPointerTy()) {
 	 		srcText = getPointerTo(val, locals);
+	 	// non-ptr values can go by name
+	 	} else if (srcDesc) {
+	 		srcText = srcDesc->name;
 	 	} else if (llvm::isa<llvm::Constant>(val)) {
 	 		srcText = getConstant(llvm::cast<llvm::Constant>(val), locals);
 	 	} else {
 	 {
 	 	bool isDereffed;
 	 	std::string core = unwindPointer(val, locals, isDereffed, rootName);
+	 	std::cerr << "[DEREF] getRet core " << core << " isDereffed " << isDereffed << "\n";
 	 	if (isDereffed) {
 	 		return core;
 	 	} else {

lib/axtor_ocl/OCLWriter.cpp

 	//byval function arguments don't need be dereferenced
 	if (llvm::isa<llvm::Argument>(rootValue))
 	{
+#ifdef DEBUG
+		std::cerr << "DEREF: argument case\n";
+#endif
 		llvm::Argument * arg = llvm::cast<llvm::Argument>(rootValue);
 		hasImplicitPtrDeref |= arg->hasByValAttr();
 	}
 
 	//local variables are initialised in the program, so assume implicit deref
 	if (llvm::isa<llvm::GlobalVariable>(rootValue)) {
+#ifdef DEBUG
+		std::cerr << "DEREF: Global case\n";
+#endif
+
 		llvm::GlobalVariable * gv = llvm::cast<llvm::GlobalVariable>(rootValue);
 		hasImplicitPtrDeref |= gv->isConstant() || gv->getType()->getAddressSpace() == SPACE_LOCAL || gv->getType()->getAddressSpace() == SPACE_CONSTANT;
 	}
 	if (rootName) {
 		tmp = *rootName;
 
-	} else if (llvm::isa<llvm::ConstantExpr>(rootValue)) {
+	} else if (llvm::isa<llvm::Constant>(rootValue)) {
 		tmp = getConstant(llvm::cast<llvm::Constant>(rootValue), locals);
 
 	} else {
 
 	  // this is a pointer
 	  if (!address) {
+#ifdef DEBUG
+		std::cerr << "DEREF: real pointer case. deref: " << hasImplicitPtrDeref << "\n";
+#endif
+
 		  oDereferenced = hasImplicitPtrDeref;
 		  return tmp;
 	  }
 			case llvm::Type::FloatTyID:
 				return "0.0f";
 
+			case llvm::Type::PointerTyID:
+				Log::warn(type, "Using null pointer literal");
 			case llvm::Type::IntegerTyID:
 				return "0";
 
 			writeAssignRaw(name, srcString);
 		} else {
 			std::string name = getReferenceTo(pointer, locals);
+			std::cerr << "store to " << name << "\n";
 			writeAssignRaw(name, srcString);
 		}
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.