diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5048,7 +5048,8 @@
   // to the function type.
   if (isa<FunctionNoProtoType>(FnType) || Chain) {
     llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo);
-    CalleeTy = CalleeTy->getPointerTo();
+    int AS = getTypes().getDataLayout().getProgramAddressSpace();
+    CalleeTy = CalleeTy->getPointerTo(AS);
 
     llvm::Value *CalleePtr = Callee.getFunctionPointer();
     CalleePtr = Builder.CreateBitCast(CalleePtr, CalleeTy, "callee.knr.cast");
diff --git a/clang/test/CodeGen/address-space-avr.c b/clang/test/CodeGen/address-space-avr.c
new file mode 100644
--- /dev/null
+++ b/clang/test/CodeGen/address-space-avr.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s
+
+// CHECK: define void @bar() addrspace(1)
+// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to void (i16) addrspace(1)*)(i16 3)
+// CHECK: declare void @foo(...) addrspace(1)
+void foo();
+void bar(void) {
+	foo(3);
+}