]> granicus.if.org Git - clang/commitdiff
Make constant emission for @encode use the common string emission code.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 7 Mar 2009 20:17:55 +0000 (20:17 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 7 Mar 2009 20:17:55 +0000 (20:17 +0000)
This is a bit cleaner, and also "fixes" bad code that compares the
addresses of the string constants.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66346 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenObjC/encode-test-4.m [new file with mode: 0644]

index 95d881bc49a3e2e7e15c1bed1f3e53e8cf5242e8..16ba94791fad30f5649157d76caf0b2cbef0a44a 100644 (file)
@@ -1132,12 +1132,8 @@ llvm::Constant *
 CodeGenModule::GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *E) {
   std::string Str;
   getContext().getObjCEncodingForType(E->getEncodedType(), Str);
-  
-  llvm::Constant *C = llvm::ConstantArray::get(Str);
-  C = new llvm::GlobalVariable(C->getType(), true, 
-                               llvm::GlobalValue::InternalLinkage,
-                               C, ".str", &getModule());
-  return C;
+
+  return GetAddrOfConstantCString(Str);
 }
 
 
diff --git a/test/CodeGenObjC/encode-test-4.m b/test/CodeGenObjC/encode-test-4.m
new file mode 100644 (file)
index 0000000..4d39a53
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm -o - %s -O2 | grep "ret i32 1"
+
+int a() {
+  return @encode(int) == @encode(int);
+}