================
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck 
%s
+
+typedef __SIZE_TYPE__ size_t;
+
+int printf(const char * _Format, ...);
+char *strcpy(char *s1, const char *s2);
+
+struct S {
+  S();
+  int a[4];
+};
+
+// CHECK: define {{.*}} @_Z5test1PKc
+// CHECK: %a = alloca [1000 x i8], align {{.*}}, !stack-protector ![[A:.*]]
+void test1(const char *msg) {
+  __attribute__((stack_protector_ignore))
+  char a[1000];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
+// CHECK: define {{.*}} @_Z5test2
+// CHECK-NOT: %b = alloca [1000 x i8], align {{.*}}, !stack-protector
+void test2(const char *msg) {
+  char b[1000];
+  strcpy(b, msg);
+  printf("%s\n", b);
+}
+
+// CHECK: define {{.*}} @_Z5test3v
+// CHECK-NOT: %b = alloca [1000 x i8], align {{.*}}, !stack-protector
----------------
ahatanak wrote:

> Fixed. I had to find a different place to check for the attribute on NRVO. 
> Ended up in where we handle return statements as that has access to the 
> original VarDecl to query the attributes.
> 

Is it not possible to check the attribute on VarDecl after the else branch 
instead of adding a separate check in `CodeGenFunction::EmitReturnStmt`?

```
      if (NRVO) {
        ...
      } else {
        ...
      }
      if (D.hasAttr<StackProtectorIgnoreAttr>()) {
        if (auto *AI = dyn_cast<llvm::AllocaInst>(address.getBasePointer())) {
          llvm::LLVMContext &Ctx = Builder.getContext();
          auto *Operand = llvm::ConstantAsMetadata::get(Builder.getInt32(0));
          AI->setMetadata("stack-protector", llvm::MDNode::get(Ctx, {Operand}));
        }
      } 
```

https://github.com/llvm/llvm-project/pull/173311
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to