Re: r283063 - Alias must point to a definition

2016-10-03 Thread Aditya K via cfe-commits
Thanks for poining that out. I have updated the test case, please see if that 
works.


http://llvm.org/viewvc/llvm-project?view=revision&revision=283085



-Aditya



From: Yaron Keren 
Sent: Sunday, October 2, 2016 11:32 AM
To: Aditya Kumar
Cc: cfe-commits
Subject: Re: r283063 - Alias must point to a definition

The mangling is different when targeting MSVC ABI, see failure at

http://bb.pgr.jp/builders/ninja-x64-msvc-RA-centos6/builds/29889/steps/test_all/logs/Clang%20%3A%3A%20CodeGenCXX__alias-available-externally.cpp

maybe   -triple x86_64-pc-linux  ?

2016-10-02 6:06 GMT+03:00 Aditya Kumar via cfe-commits 
mailto:cfe-commits@lists.llvm.org>>:
Author: hiraditya
Date: Sat Oct  1 22:06:36 2016
New Revision: 283063

URL: http://llvm.org/viewvc/llvm-project?rev=283063&view=rev
Log:
Alias must point to a definition

Reapplying the patch after modifying the test case.

Inlining the destructor caused the compiler to generate bad IR which failed the 
Verifier in the backend.
https://llvm.org/bugs/show_bug.cgi?id=30341

This patch disables alias to available_externally definitions.

Reviewers: eugenis, rsmith

Differential Revision: https://reviews.llvm.org/D24682

Added:
cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=283063&r1=283062&r2=283063&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sat Oct  1 22:06:36 2016
@@ -134,6 +134,11 @@ bool CodeGenModule::TryEmitDefinitionAsA
   llvm::GlobalValue::LinkageTypes TargetLinkage =
   getFunctionLinkage(TargetDecl);

+  // available_externally definitions aren't real definitions, so we cannot
+  // create an alias to one.
+  if (TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage)
+return true;
+
   // Check if we have it already.
   StringRef MangledName = getMangledName(AliasDecl);
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
@@ -156,14 +161,7 @@ bool CodeGenModule::TryEmitDefinitionAsA

   // Instead of creating as alias to a linkonce_odr, replace all of the uses
   // of the aliasee.
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
- (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
-  !TargetDecl.getDecl()->hasAttr())) {
-// FIXME: An extern template instantiation will create functions with
-// linkage "AvailableExternally". In libc++, some classes also define
-// members with attribute "AlwaysInline" and expect no reference to
-// be generated. It is desirable to reenable this optimisation after
-// corresponding LLVM changes.
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
 addReplacement(MangledName, Aliasee);
 return false;
   }

Added: cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp?rev=283063&view=auto
==
--- cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/alias-available-externally.cpp Sat Oct  1 
22:06:36 2016
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -O1 -std=c++11 -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+// Clang should not generate alias to available_externally definitions.
+// Check that the destructor of Foo is defined.
+// The destructors have different return type for different targets.
+// CHECK: define linkonce_odr {{.*}} @_ZN3FooD2Ev
+template 
+struct String {
+  String() {}
+  ~String();
+};
+
+template 
+inline __attribute__((visibility("hidden"), always_inline))
+String::~String() {}
+
+extern template struct String;
+
+struct Foo : public String { Foo() { String s; } };
+
+Foo f;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D9924: Ignore report when the argument to malloc is assigned known value

2015-08-17 Thread Aditya K via cfe-commits



> Date: Mon, 17 Aug 2015 19:29:29 +
> To: hiradi...@msn.com; jordan_r...@apple.com; kreme...@apple.com; 
> daniel.marjam...@evidente.se; mclow.li...@gmail.com; adasg...@codeaurora.org; 
> zaks.a...@gmail.com
> From: zaks.a...@gmail.com
> CC: cfe-commits@lists.llvm.org
> Subject: Re: [PATCH] D9924: Ignore report when the argument to malloc is 
> assigned known value
>
> zaks.anna added a comment.
>
>> x = a/b; where n < b
>
>> malloc (x*n); Then x*n will not overflow
>
>
> I am not convinced that the new rule is strong enough. 'a' can be any 
> expression. For example, maybe you have (b-1)*a/b and the denominator cancels 
> out something unrelated to 'n' in the numerator? Maybe we could change the 
> rule to "where n==b"? By the way, that is the only subcase that is being 
> tested.

Please correct me if I'm wrong.
My point was, as long as `n x*n < a which does not overflow.

Maybe, I should add a check that `a, b, n' are positive.
So, in this case static analyzer can choose to be strict and reject false 
positives.

If `a' might overflow, then in this case we can emit warning stating that the 
overflow is caused because `a' might overflow.

>
>> With regards to copy paste, I'm not sure about how to do this in a different 
>> way.
>
>
> I suggest to experiment with refactoring out common parts into subroutines.

Thanks, I'll try to refactor parts of it.
-Aditya

>
>
> http://reviews.llvm.org/D9924
>
>
>
  
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D9924: Ignore report when the argument to malloc is assigned known value

2015-08-17 Thread Aditya K via cfe-commits



> Date: Mon, 17 Aug 2015 21:39:32 +
> To: hiradi...@msn.com; jordan_r...@apple.com; kreme...@apple.com; 
> daniel.marjam...@evidente.se; mclow.li...@gmail.com; adasg...@codeaurora.org; 
> zaks.a...@gmail.com
> From: zaks.a...@gmail.com
> CC: cfe-commits@lists.llvm.org
> Subject: Re: [PATCH] D9924: Ignore report when the argument to malloc is 
> assigned known value
>
> zaks.anna added a comment.
>
>> Maybe, I should add a check that `a, b, n' are positive.
>
>> So, in this case static analyzer can choose to be strict and reject false 
>> positives.
>
>
> What would this buy us? Does the checker warn on underflow?

I mean, checking `a,b,n' are positive would ensure that there is no overflow in 
this case and then we would not emit report.
The checker does not warn on underflow, so we can ignore checking `a,b,n' are 
positive, if it is too complicated.

>
>> If a' might overflow, then in this case we can emit warning stating that the 
>> overflow is caused because a' might overflow.
>
>
> I see your point now! I think we should improve the diagnostic that is 
> produced in this case!

I'm trying to implement that.
Thanks,
-Aditya

>
>
> http://reviews.llvm.org/D9924
>
>
>
  
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits