[clang] 0e5fe1c - Remove `REQUIRES: x86-registered-target` from ps4/ps5 driver tests

2022-08-31 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2022-08-31T09:56:37+01:00
New Revision: 0e5fe1cdacdca65edc84c89cc7a6de27f406de61

URL: 
https://github.com/llvm/llvm-project/commit/0e5fe1cdacdca65edc84c89cc7a6de27f406de61
DIFF: 
https://github.com/llvm/llvm-project/commit/0e5fe1cdacdca65edc84c89cc7a6de27f406de61.diff

LOG: Remove `REQUIRES: x86-registered-target` from ps4/ps5 driver tests

Reviewed By: probinson

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

Added: 


Modified: 
clang/test/Driver/ps4-pic.c
clang/test/Driver/ps4-ps5-header-search.c
clang/test/Driver/ps4-ps5-linker-non-win.c
clang/test/Driver/ps4-ps5-linker-win.c
clang/test/Driver/ps4-ps5-relax-relocations.c
clang/test/Driver/ps4-ps5-runtime-flags.c
clang/test/Driver/ps4-sdk-root.c
clang/test/Driver/ps4ps5base.c
clang/test/Driver/ps5-pic.c
clang/test/Driver/ps5-sdk-root.c

Removed: 




diff  --git a/clang/test/Driver/ps4-pic.c b/clang/test/Driver/ps4-pic.c
index c023dcfd0c35..fc429f130c75 100644
--- a/clang/test/Driver/ps4-pic.c
+++ b/clang/test/Driver/ps4-pic.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target
-
 // Test the driver's control over the PIC behavior for PS4 compiler.
 // These consist of tests of the relocation model flags and the
 // pic level flags passed to CC1.

diff  --git a/clang/test/Driver/ps4-ps5-header-search.c 
b/clang/test/Driver/ps4-ps5-header-search.c
index 6848901df559..6762c707dde6 100644
--- a/clang/test/Driver/ps4-ps5-header-search.c
+++ b/clang/test/Driver/ps4-ps5-header-search.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target
-
 /// PS4 and PS5 use the same SDK layout, so use the same tree for both.
 // RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
 // RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4

diff  --git a/clang/test/Driver/ps4-ps5-linker-non-win.c 
b/clang/test/Driver/ps4-ps5-linker-non-win.c
index b9686b88a757..8b8c0b018428 100644
--- a/clang/test/Driver/ps4-ps5-linker-non-win.c
+++ b/clang/test/Driver/ps4-ps5-linker-non-win.c
@@ -1,6 +1,5 @@
 /// Checks proper linker prefixing for PS4 and PS5.
 // UNSUPPORTED: system-windows
-// REQUIRES: x86-registered-target
 
 // RUN: mkdir -p %t
 // RUN: rm -f %t/orbis-ld

diff  --git a/clang/test/Driver/ps4-ps5-linker-win.c 
b/clang/test/Driver/ps4-ps5-linker-win.c
index acff2c0f1f24..f02f5a2055ec 100644
--- a/clang/test/Driver/ps4-ps5-linker-win.c
+++ b/clang/test/Driver/ps4-ps5-linker-win.c
@@ -1,7 +1,7 @@
 // This test checks that orbis-ld is used for PS4 linker all the time, and
 // prospero-lld is used for PS5 linker. Specifying -fuse-ld causes an error.
 
-// REQUIRES: system-windows, x86-registered-target
+// REQUIRES: system-windows
 
 // RUN: mkdir -p %t
 // RUN: touch %t/orbis-ld.exe

diff  --git a/clang/test/Driver/ps4-ps5-relax-relocations.c 
b/clang/test/Driver/ps4-ps5-relax-relocations.c
index 1c8200a6d58b..22490e486052 100644
--- a/clang/test/Driver/ps4-ps5-relax-relocations.c
+++ b/clang/test/Driver/ps4-ps5-relax-relocations.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target
-
 // RUN: %clang -### -target x86_64-scei-ps4 %s -o - 2>&1 | \
 // RUN:   FileCheck %s
 // RUN: %clang -### -target x86_64-scei-ps4 -Wa,-mrelax-relocations=yes %s -o 
- 2>&1 | \

diff  --git a/clang/test/Driver/ps4-ps5-runtime-flags.c 
b/clang/test/Driver/ps4-ps5-runtime-flags.c
index 96c9c1244ddd..e75ba97948d2 100644
--- a/clang/test/Driver/ps4-ps5-runtime-flags.c
+++ b/clang/test/Driver/ps4-ps5-runtime-flags.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target
-//
 /// Test the profile runtime library to be linked for PS4/PS5 compiler.
 /// Check runtime flag --dependent-lib which does not append the default 
library search path.
 //

diff  --git a/clang/test/Driver/ps4-sdk-root.c 
b/clang/test/Driver/ps4-sdk-root.c
index ee22d6c8f0cf..e1a04522030c 100644
--- a/clang/test/Driver/ps4-sdk-root.c
+++ b/clang/test/Driver/ps4-sdk-root.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target
-
 // Check that PS4 clang doesn't report a warning message when locating
 // system header files (either by looking at the value of SCE_ORBIS_SDK_DIR
 // or relative to the location of the compiler driver), if "-nostdinc",

diff  --git a/clang/test/Driver/ps4ps5base.c b/clang/test/Driver/ps4ps5base.c
index bd583f88dd6e..a688c250129f 100644
--- a/clang/test/Driver/ps4ps5base.c
+++ b/clang/test/Driver/ps4ps5base.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target
-
 // Test that the driver always emits -fno-use-init-array on the PS4/PS5 targets
 // since their ABI does not support the .init_array section.
 

diff  --git a/clang/test/Driver/ps5-pic.c b/clang/test/Driver/ps5-pic.c
index 0396122accf4..4db107cd8c86 100644
--- a/clang/test/Driver/ps5-pic.c
+++ b/clang/test/Driver/ps5-pic.c
@@ -1,5 +1

[clang] 41b1c9f - Re-add the REQUIRES line to fix a failed build on builder llvm-clang-win-x-aarch64.

2022-08-31 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2022-08-31T20:22:18+01:00
New Revision: 41b1c9ff70142dc38a381517718cd3f95e8d62b7

URL: 
https://github.com/llvm/llvm-project/commit/41b1c9ff70142dc38a381517718cd3f95e8d62b7
DIFF: 
https://github.com/llvm/llvm-project/commit/41b1c9ff70142dc38a381517718cd3f95e8d62b7.diff

LOG: Re-add the REQUIRES line to fix a failed build on builder 
llvm-clang-win-x-aarch64.

Added: 


Modified: 
clang/test/Driver/ps4-ps5-header-search.c

Removed: 




diff  --git a/clang/test/Driver/ps4-ps5-header-search.c 
b/clang/test/Driver/ps4-ps5-header-search.c
index 6762c707dde6..6848901df559 100644
--- a/clang/test/Driver/ps4-ps5-header-search.c
+++ b/clang/test/Driver/ps4-ps5-header-search.c
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+
 /// PS4 and PS5 use the same SDK layout, so use the same tree for both.
 // RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
 // RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4



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


[clang] 5de4d97 - Driver tests: remove `REQUIRES: x86-registered-target` and set `--sysroot=""` to support clang with `DEFAULT_SYSROOT`.

2022-09-05 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2022-09-05T09:59:47+01:00
New Revision: 5de4d97a00b2a5d710892e96d77810784fd2cd5c

URL: 
https://github.com/llvm/llvm-project/commit/5de4d97a00b2a5d710892e96d77810784fd2cd5c
DIFF: 
https://github.com/llvm/llvm-project/commit/5de4d97a00b2a5d710892e96d77810784fd2cd5c.diff

LOG: Driver tests: remove `REQUIRES: x86-registered-target` and set 
`--sysroot=""` to support clang with `DEFAULT_SYSROOT`.

When testing clang that has been compiled with -DDEFAULT_SYSROOT set to some 
path, ps4-ps5-header-search.c would fail.

The test needs to be updated.

1. Remove unnecessary REQUIRES: x86-registered-target.
2. Override sysroot to be empty string for the test to succeed when clang 
is configured with DEFAULT_SYSROOT.

Added: 


Modified: 
clang/test/Driver/ps4-ps5-header-search.c

Removed: 




diff  --git a/clang/test/Driver/ps4-ps5-header-search.c 
b/clang/test/Driver/ps4-ps5-header-search.c
index 6848901df5590..59d3f2ab2d1df 100644
--- a/clang/test/Driver/ps4-ps5-header-search.c
+++ b/clang/test/Driver/ps4-ps5-header-search.c
@@ -1,8 +1,6 @@
-// REQUIRES: x86-registered-target
-
 /// PS4 and PS5 use the same SDK layout, so use the same tree for both.
-// RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
-// RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
+// RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-scei-ps4 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
+// RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target 
x86_64-sie-ps5 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
 // ENVPS4: Inputs/scei-ps4_tree/target/include{{$}}
 // ENVPS4: Inputs/scei-ps4_tree/target/include_common{{$}}
 // ENVPS4-NOT: /usr/include



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


[clang] 33b8586 - Add two time-trace scope variables.

2023-10-31 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2023-10-31T09:16:06Z
New Revision: 33b85867e30e1adc2ff2173039c199b81c10f52b

URL: 
https://github.com/llvm/llvm-project/commit/33b85867e30e1adc2ff2173039c199b81c10f52b
DIFF: 
https://github.com/llvm/llvm-project/commit/33b85867e30e1adc2ff2173039c199b81c10f52b.diff

LOG: Add two time-trace scope variables.

A time trace scope variable of `ParseDeclarationOrFunctionDefinition`
with the function's source location is added to record the time spent
parsing the function's declaration or definition. Another time trace
scope variable of `ParseFunctionDefinition` is also added to record the
name of the defined function. A release note is added as well.

Reviewed by: Aaron Ballman
Pull request: #65268

Added: 
clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/Parser.cpp
clang/unittests/Support/TimeProfilerTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc28bb567f6932a..c151bd9d234b51e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -427,6 +427,14 @@ Improvements to Clang's diagnostics
   (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to 
be more consistent
   with GCC.
 
+Improvements to Clang's time-trace
+--
+- Two time-trace scope variables are added. A time trace scope variable of
+  ``ParseDeclarationOrFunctionDefinition`` with the function's source location
+  is added to record the time spent parsing the function's declaration or
+  definition. Another time trace scope variable of ``ParseFunctionDefinition``
+  is also added to record the name of the defined function.
+
 Bug Fixes in This Version
 -
 - Fixed an issue where a class template specialization whose declaration is

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 0f930248e77174b..bef3a0dcb285efd 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -13,8 +13,8 @@
 #include "clang/Parse/Parser.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Parse/ParseDiagnostic.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
@@ -22,6 +22,7 @@
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
 
@@ -1229,6 +1230,13 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclOrFunctionDefInternal(
 Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition(
 ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs,
 ParsingDeclSpec *DS, AccessSpecifier AS) {
+  // Add an enclosing time trace scope for a bunch of small scopes with
+  // "EvaluateAsConstExpr".
+  llvm::TimeTraceScope TimeScope(
+  "ParseDeclarationOrFunctionDefinition",
+  Tok.getLocation().printToString(
+  Actions.getASTContext().getSourceManager()));
+
   if (DS) {
 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
   } else {
@@ -1259,6 +1267,10 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclarationOrFunctionDefinition(
 Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
   const ParsedTemplateInfo &TemplateInfo,
   LateParsedAttrList *LateParsedAttrs) {
+  llvm::TimeTraceScope TimeScope(
+  "ParseFunctionDefinition",
+  Actions.GetNameForDeclarator(D).getName().getAsString());
+
   // Poison SEH identifiers so they are flagged as illegal in function bodies.
   PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true);
   const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();

diff  --git 
a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp 
b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp
new file mode 100644
index 000..f854cddadbfcc1d
--- /dev/null
+++ 
b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp
@@ -0,0 +1,15 @@
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o 
%T/check-time-trace-ParseDeclarationOrFunctionDefinition %s
+// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \
+// RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN:   | FileCheck %s
+
+// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition"
+// CHECK-DAG: "detail": 
"{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1"
+// CHECK-DAG: "name": "ParseFunctionDefinition"
+// CHECK-DAG: "detail": "foo"
+// CHECK-DAG: "name": "ParseFunctionDe

[clang] 700d93b - Add two time-trace scope variables.

2023-11-01 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2023-11-01T13:37:52Z
New Revision: 700d93b0584c9d6401ec646fc3e343e90f326fa2

URL: 
https://github.com/llvm/llvm-project/commit/700d93b0584c9d6401ec646fc3e343e90f326fa2
DIFF: 
https://github.com/llvm/llvm-project/commit/700d93b0584c9d6401ec646fc3e343e90f326fa2.diff

LOG: Add two time-trace scope variables.

A time trace scope variable of `ParseDeclarationOrFunctionDefinition`
with the function's source location is added to record the time spent
parsing the function's declaration or definition. Another time trace
scope variable of `ParseFunctionDefinition` is also added to record the
name of the defined function. A release note is added as well.

Reviewed by: Aaron Ballman
Pull request: #65268

Added: 
clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/Parser.cpp
clang/unittests/Support/TimeProfilerTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89c35af565fdeef..103dcbeb79624d9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -427,6 +427,14 @@ Improvements to Clang's diagnostics
   (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to 
be more consistent
   with GCC.
 
+Improvements to Clang's time-trace
+--
+- Two time-trace scope variables are added. A time trace scope variable of
+  ``ParseDeclarationOrFunctionDefinition`` with the function's source location
+  is added to record the time spent parsing the function's declaration or
+  definition. Another time trace scope variable of ``ParseFunctionDefinition``
+  is also added to record the name of the defined function.
+
 Bug Fixes in This Version
 -
 - Fixed an issue where a class template specialization whose declaration is

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 0f930248e77174b..176d2149e73184e 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -13,8 +13,8 @@
 #include "clang/Parse/Parser.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Parse/ParseDiagnostic.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
@@ -22,6 +22,7 @@
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
 
@@ -1229,6 +1230,13 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclOrFunctionDefInternal(
 Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition(
 ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs,
 ParsingDeclSpec *DS, AccessSpecifier AS) {
+  // Add an enclosing time trace scope for a bunch of small scopes with
+  // "EvaluateAsConstExpr".
+  llvm::TimeTraceScope TimeScope("ParseDeclarationOrFunctionDefinition", [&]() 
{
+return Tok.getLocation().printToString(
+Actions.getASTContext().getSourceManager());
+  });
+
   if (DS) {
 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
   } else {
@@ -1259,6 +1267,10 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclarationOrFunctionDefinition(
 Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
   const ParsedTemplateInfo &TemplateInfo,
   LateParsedAttrList *LateParsedAttrs) {
+  llvm::TimeTraceScope TimeScope("ParseFunctionDefinition", [&]() {
+return Actions.GetNameForDeclarator(D).getName().getAsString();
+  });
+
   // Poison SEH identifiers so they are flagged as illegal in function bodies.
   PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true);
   const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();

diff  --git 
a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp 
b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp
new file mode 100644
index 000..f854cddadbfcc1d
--- /dev/null
+++ 
b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp
@@ -0,0 +1,15 @@
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o 
%T/check-time-trace-ParseDeclarationOrFunctionDefinition %s
+// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \
+// RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN:   | FileCheck %s
+
+// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition"
+// CHECK-DAG: "detail": 
"{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1"
+// CHECK-DAG: "name": "ParseFunctionDefinition"
+// CHECK-DAG: "detail": "foo"
+// CHECK-DAG: "na

[clang] bfe191d - Disable stack-sizes section by default for PS4.

2022-07-27 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2022-07-27T09:37:20+01:00
New Revision: bfe191dfa79bbccb57506055db9c89bfb891f65c

URL: 
https://github.com/llvm/llvm-project/commit/bfe191dfa79bbccb57506055db9c89bfb891f65c
DIFF: 
https://github.com/llvm/llvm-project/commit/bfe191dfa79bbccb57506055db9c89bfb891f65c.diff

LOG: Disable stack-sizes section by default for PS4.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/stack-size-section.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b62a025c5072..d3ff71ee28e9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5886,9 +5886,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(A->getValue());
   }
 
-  if (Args.hasFlag(options::OPT_fstack_size_section,
-   options::OPT_fno_stack_size_section, RawTriple.isPS4()))
-CmdArgs.push_back("-fstack-size-section");
+  Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
+options::OPT_fno_stack_size_section);
 
   if (Args.hasArg(options::OPT_fstack_usage)) {
 CmdArgs.push_back("-stack-usage-file");

diff  --git a/clang/test/Driver/stack-size-section.c 
b/clang/test/Driver/stack-size-section.c
index f50c9767e707..b99b1409bef4 100644
--- a/clang/test/Driver/stack-size-section.c
+++ b/clang/test/Driver/stack-size-section.c
@@ -4,7 +4,7 @@
 // CHECK-ABSENT-NOT: -fstack-size-section
 
 // RUN: %clang -target x86_64-unknown -fstack-size-section -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-PRESENT
-// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PRESENT
+// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ABSENT
 // CHECK-PRESENT: -fstack-size-section
 
 // RUN: %clang -target x86_64-unknown -fstack-size-section 
-fno-stack-size-section %s -### 2>&1 \



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


[clang] b09ba42 - Bug 51277: [DWARF] DW_AT_alignment incorrect when

2022-04-22 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2022-04-22T12:15:00+01:00
New Revision: b09ba42620768c0092b20cf526a30b14752a5dc9

URL: 
https://github.com/llvm/llvm-project/commit/b09ba42620768c0092b20cf526a30b14752a5dc9
DIFF: 
https://github.com/llvm/llvm-project/commit/b09ba42620768c0092b20cf526a30b14752a5dc9.diff

LOG: Bug 51277: [DWARF] DW_AT_alignment incorrect when
attribute((__aligned__)) is present but ignored`

In the original code, the 'getDeclAlignIfRequired' function is used.
The 'getDeclAlignIfRequired' function will return the max alignment
of all aligned attributes if the type has aligned attributes. The
function doesn't consider the type at all.

The 'getTypeAlignIfRequired' function uses the type's alignment value,
which also used by the 'alignof' function. I think we should use the
function of 'getTypeAlignIfRequired'.

Reviewed By: dblaikie, jmorse, wolfgangp

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

Added: 
clang/test/CodeGenCXX/debug-info-struct-align.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 846b9db76dd4a..a6ea2c0f31abf 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3561,7 +3561,11 @@ llvm::DICompositeType 
*CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
 return getOrCreateRecordFwdDecl(Ty, RDContext);
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
-  auto Align = getDeclAlignIfRequired(D, CGM.getContext());
+  // __attribute__((aligned)) can increase or decrease alignment *except* on a
+  // struct or struct member, where it only increases  alignment unless 
'packed'
+  // is also specified. To handle this case, the `getTypeAlignIfRequired` needs
+  // to be used.
+  auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
 
   SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
 

diff  --git a/clang/test/CodeGenCXX/debug-info-struct-align.cpp 
b/clang/test/CodeGenCXX/debug-info-struct-align.cpp
new file mode 100644
index 0..6d75c71476ba1
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-struct-align.cpp
@@ -0,0 +1,27 @@
+//  Test for debug info related to DW_AT_alignment attribute in the struct 
type.
+// RUN: %clang_cc1 -dwarf-version=5 -debug-info-kind=standalone -S -emit-llvm 
%s -o - | FileCheck %s
+
+// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType", 
{{.*}}, align: 32
+// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType1", 
{{.*}}, align: 8
+// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType2", 
{{.*}}, align: 8
+
+struct MyType {
+  int m;
+} __attribute__((aligned(1)));
+MyType mt;
+
+static_assert(alignof(MyType) == 4, "alignof MyType is wrong");
+
+struct MyType1 {
+  int m;
+} __attribute__((packed, aligned(1)));
+MyType1 mt1;
+
+static_assert(alignof(MyType1) == 1, "alignof MyType1 is wrong");
+
+struct MyType2 {
+  __attribute__((packed)) int m;
+} __attribute__((aligned(1)));
+MyType2 mt2;
+
+static_assert(alignof(MyType2) == 1, "alignof MyType2 is wrong");



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


[clang] 9ef536a - [UBSan] Disable the function and kcfi sanitizers on an execute-only target.

2023-08-30 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2023-08-30T17:17:37+01:00
New Revision: 9ef536a12ea65a2b9e2511936327c7b621af38fb

URL: 
https://github.com/llvm/llvm-project/commit/9ef536a12ea65a2b9e2511936327c7b621af38fb
DIFF: 
https://github.com/llvm/llvm-project/commit/9ef536a12ea65a2b9e2511936327c7b621af38fb.diff

LOG: [UBSan] Disable the function and kcfi sanitizers on an execute-only target.

An execute-only target disallows data access to code sections.
-fsanitize=function and -fsanitize=kcfi instrument indirect function
calls to load a type hash before the function label. This results in a
non-execute access to the code section and a runtime error.

To solve the issue, -fsanitize=function should not be included in any
check group (e.g. undefined) on an execute-only target. If a user passes
-fsanitize=undefined, there is no error and no warning. However, if the
user explicitly passes -fsanitize=function or -fsanitize=kcfi on an
execute-only target, an error will be emitted.

Fixes: https://github.com/llvm/llvm-project/issues/64931.

Reviewed By: MaskRay, probinson, simon_tatham

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

Added: 


Modified: 
clang/include/clang/Basic/Sanitizers.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Sanitizers.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGenObjCXX/crash-function-type.mm
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/include/clang/Basic/Sanitizers.h 
b/clang/include/clang/Basic/Sanitizers.h
index db53010645ae3b..c212f80fe03adc 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -23,7 +23,11 @@
 
 namespace llvm {
 class hash_code;
+class Triple;
+namespace opt {
+class ArgList;
 }
+} // namespace llvm
 
 namespace clang {
 
@@ -205,6 +209,11 @@ StringRef AsanDetectStackUseAfterReturnModeToString(
 llvm::AsanDetectStackUseAfterReturnMode
 AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr);
 
+/// Return true if an execute-only target disallows data access to code
+/// sections.
+bool isExecuteOnlyTarget(const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_SANITIZERS_H

diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index db59d7dd96da0a..f93ee707dab470 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  Option
   Support
   TargetParser
   )

diff  --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sanitizers.cpp
index 62ccdf8e9bbf28..6fbc32df314896 100644
--- a/clang/lib/Basic/Sanitizers.cpp
+++ b/clang/lib/Basic/Sanitizers.cpp
@@ -11,10 +11,13 @@
 
//===--===//
 
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Driver/Options.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/TargetParser/Triple.h"
 
 using namespace clang;
 
@@ -112,4 +115,14 @@ AsanDetectStackUseAfterReturnModeFromString(StringRef 
modeStr) {
   .Default(llvm::AsanDetectStackUseAfterReturnMode::Invalid);
 }
 
+bool isExecuteOnlyTarget(const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args) {
+  if (Triple.isPS5())
+return true;
+
+  // On Arm, the clang `-mexecute-only` option is used to generate the
+  // execute-only output (no data access to code sections).
+  return Args.hasFlag(clang::driver::options::OPT_mexecute_only,
+  clang::driver::options::OPT_mno_execute_only, false);
+}
 } // namespace clang

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 12f7e9fb9d2966..71968a47fbf4fc 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -37,6 +37,8 @@ static const SanitizerMask NeedsUbsanCxxRt =
 SanitizerKind::Vptr | SanitizerKind::CFI;
 static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
 static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
+static const SanitizerMask NotAllowedWithExecuteOnly =
+SanitizerKind::Function | SanitizerKind::KCFI;
 static const SanitizerMask RequiresPIE =
 SanitizerKind::DataFlow | SanitizerKind::Scudo;
 static const SanitizerMask NeedsUnwindTables =
@@ -395,6 +397,22 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   DiagnosedKinds |= SanitizerKind::Function;
 }
   }
+  // -fsanitize=function and -fsanitize=kcfi instrument indirect function
+  // calls to load a type hash before the function label. Therefore, an
+  // execute-only target doesn't support the function and kcfi sanitizers.
+  const llvm::Triple &Triple = TC.getTriple();
+

[clang] 94dd476 - [Coverage] Fix an issue: a statement after calling 'assert()' function is wrongly

2023-03-02 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2023-03-02T09:14:44Z
New Revision: 94dd4766a61bb18b263415e17e745dc2fa609162

URL: 
https://github.com/llvm/llvm-project/commit/94dd4766a61bb18b263415e17e745dc2fa609162
DIFF: 
https://github.com/llvm/llvm-project/commit/94dd4766a61bb18b263415e17e745dc2fa609162.diff

LOG: [Coverage] Fix an issue: a statement after calling 'assert()' function is 
wrongly
marked as 'not executed'.

In the current coverage mapping implementation, we terminate the current region
and start a zero region when we hit a nonreturn function. However, for logical 
OR,
the second operand is not executed if the first operand evaluates to true. If 
the
nonreturn function is called in the right side of logical OR and the left side 
of
logical OR is TRUE, we should not start a zero `GapRegionCounter`. This will 
also
apply to `VisitAbstractConditionalOperator`.

Fixes https://github.com/llvm/llvm-project/issues/59030

Reviewed By: zequanwu

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

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/terminate-statements.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 56ff36438098..68e6457419ab 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1466,6 +1466,7 @@ struct CounterCoverageMappingBuilder
 Counter TrueCount = getRegionCounter(E);
 
 propagateCounts(ParentCount, E->getCond());
+Counter OutCount;
 
 if (!isa(E)) {
   // The 'then' count applies to the area immediately after the condition.
@@ -1475,12 +1476,18 @@ struct CounterCoverageMappingBuilder
 fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), TrueCount);
 
   extendRegion(E->getTrueExpr());
-  propagateCounts(TrueCount, E->getTrueExpr());
+  OutCount = propagateCounts(TrueCount, E->getTrueExpr());
 }
 
 extendRegion(E->getFalseExpr());
-propagateCounts(subtractCounters(ParentCount, TrueCount),
-E->getFalseExpr());
+OutCount = addCounters(
+OutCount, propagateCounts(subtractCounters(ParentCount, TrueCount),
+  E->getFalseExpr()));
+
+if (OutCount != ParentCount) {
+  pushRegion(OutCount);
+  GapRegionCounter = OutCount;
+}
 
 // Create Branch Region around condition.
 createBranchRegion(E->getCond(), TrueCount,
@@ -1514,9 +1521,19 @@ struct CounterCoverageMappingBuilder
subtractCounters(RHSExecCnt, RHSTrueCnt));
   }
 
+  // Determine whether the right side of OR operation need to be visited.
+  bool shouldVisitRHS(const Expr *LHS) {
+bool LHSIsTrue = false;
+bool LHSIsConst = false;
+if (!LHS->isValueDependent())
+  LHSIsConst = LHS->EvaluateAsBooleanCondition(
+  LHSIsTrue, CVM.getCodeGenModule().getContext());
+return !LHSIsConst || (LHSIsConst && !LHSIsTrue);
+  }
+
   void VisitBinLOr(const BinaryOperator *E) {
 extendRegion(E->getLHS());
-propagateCounts(getRegion().getCounter(), E->getLHS());
+Counter OutCount = propagateCounts(getRegion().getCounter(), E->getLHS());
 handleFileExit(getEnd(E->getLHS()));
 
 // Counter tracks the right hand side of a logical or operator.
@@ -1529,6 +1546,10 @@ struct CounterCoverageMappingBuilder
 // Extract the RHS's "False" Instance Counter.
 Counter RHSFalseCnt = getRegionCounter(E->getRHS());
 
+if (!shouldVisitRHS(E->getLHS())) {
+  GapRegionCounter = OutCount;
+}
+
 // Extract the Parent Region Counter.
 Counter ParentCnt = getRegion().getCounter();
 

diff  --git a/clang/test/CoverageMapping/terminate-statements.cpp 
b/clang/test/CoverageMapping/terminate-statements.cpp
index fa309b8efea2..0067185fee8e 100644
--- a/clang/test/CoverageMapping/terminate-statements.cpp
+++ b/clang/test/CoverageMapping/terminate-statements.cpp
@@ -320,6 +320,32 @@ void include() {
   included_func();
 }
 
+// CHECK-LABEL: _Z7ornoretv:
+void abort() __attribute__((noreturn));
+
+int ornoret(void) {
+  ( true || (abort(), 0) );  // CHECK: Gap,File 0, [[@LINE]]:28 -> 
[[@LINE+1]]:3 = #0
+  ( false || (abort(), 0) ); // CHECK: Gap,File 0, [[@LINE]]:29 -> 
[[@LINE+1]]:3 = 0
+  return 0;
+}
+
+// CHECK-LABEL: _Z17abstractcondnoretv:
+int abstractcondnoret(void) {
+  ( true ? void (0) : abort() );  // CHECK: Gap,File 0, [[@LINE]]:33 -> 
[[@LINE+1]]:3 = #1
+  ( false ? void (0) : abort() ); // CHECK: Gap,File 0, [[@LINE]]:34 -> 
[[@LINE+1]]:3 = #2
+  ( true ? abort() : void (0) );  // CHECK: Gap,File 0, [[@LINE]]:33 -> 
[[@LINE+1]]:3 = (#2 - #3)
+  ( false ? abort() : void (0) ); // CHECK: Gap,File 0, [[@LINE]]:34 -> 
[[@LINE+1]]:3 = ((#2 - #3) - #4)
+  return 0;
+}
+
+// CHECK-LABEL: _Z13elsecondnoretv:
+int elsecondnoret(void) {
+  if (true) {} else {
+true ? void (0) : abort();
+  } // C

[PATCH] D12163: [Patch] [Analyzer] BugReporter.cpp:2869: Assertion failed: !RemainingNodes.empty() && "No error node found in the trimmed graph" (PR 24184)

2015-08-19 Thread Ying Yi via cfe-commits
MaggieYi created this revision.
MaggieYi added a reviewer: krememek.
MaggieYi added a subscriber: cfe-commits.

Dear All,

I would like to propose a patch to solve an assertion failure reported by 
Dmitry in https://llvm.org/bugs/show_bug.cgi?id=24184.

The assertion is caused by reusing a “filler” ExplodedNode as an error node. 
The “filler” nodes are only used for intermediate processing and are not 
essential for analyzer history, so they can be reclaimed when the ExplodedGraph 
is trimmed by the “collectNode” function. When a checker finds a bug, they 
generate a new transition in the ExplodedGraph. The analyzer will try to reuse 
the existing predecessor node. If it cannot, it creates a new ExplodedNode, 
which always has a tag to uniquely identify the creation site. The assertion is 
caused when the analyzer reuses a “filler” node. 

In the test case, some “filler” nodes were reused and then reclaimed later when 
the ExplodedGraph was trimmed. This caused an assertion because the node was 
needed to generate the report. The “filler” nodes should not be reused as error 
nodes. The patch adds a constraint to prevent this happening, which solves the 
problem and makes the test cases pass. 

Please let me know if this is an acceptable patch.

Regards,

Ying Yi
SN Systems Ltd - Sony Computer Entertainment Group.

http://reviews.llvm.org/D12163

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  test/Analysis/PR24184.cpp
  test/Analysis/malloc.c

Index: test/Analysis/malloc.c
===
--- test/Analysis/malloc.c
+++ test/Analysis/malloc.c
@@ -1386,7 +1386,8 @@
   int *s;
   char *b = realloc(a->p, size);
   char *m = realloc(a->p, size); // expected-warning {{Attempt to free released memory}}
-  return a->p;
+  //PR24184: Object "a->p" was returned at next line after being freed by calling "realloc" at previous line.
+  return a->p; // expected-warning {{Use of memory after it is freed}}
 }
 
 // We should not warn in this case since the caller will presumably free a->p in all cases.
Index: test/Analysis/PR24184.cpp
===
--- /dev/null
+++ test/Analysis/PR24184.cpp
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -w -analyze -analyzer-eagerly-assume -fcxx-exceptions -analyzer-checker=core -analyzer-checker=alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 64 -verify %s
+// RUN: %clang_cc1 -w -analyze -analyzer-checker=core -analyzer-checker=cplusplus -fcxx-exceptions -analyzer-checker alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 63 -verify %s
+
+// These tests used to hit an assertion in the bug report. Test case from http://llvm.org/PR24184.
+typedef struct {
+  int cbData;
+  unsigned pbData;
+} CRYPT_DATA_BLOB;
+
+typedef enum { DT_NONCE_FIXED } DATA_TYPE;
+int a;
+typedef int *vcreate_t(int *, DATA_TYPE, int, int);
+void fn1(unsigned, unsigned) {
+  char b = 0;
+  for (; 1; a++, &b + a * 0) // expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous}}
+;
+}
+
+vcreate_t fn2;
+struct A {
+  CRYPT_DATA_BLOB value;
+  int m_fn1() {
+int c;
+value.pbData == 0;
+fn1(0, 0);
+  }
+};
+struct B {
+  A IkeHashAlg;
+  A IkeGType;
+  A NoncePhase1_r;
+};
+class C {
+  int m_fn2(B *);
+  void m_fn3(B *, int, int, int);
+};
+int C::m_fn2(B *p1) {
+  int *d;
+  int e = p1->IkeHashAlg.m_fn1();
+  unsigned f = p1->IkeGType.m_fn1(), h;
+  int g;
+  d = fn2(0, DT_NONCE_FIXED, (char)0, p1->NoncePhase1_r.value.cbData);
+  h = 0 | 0;
+  m_fn3(p1, 0, 0, 0);
+}
+
+// case 2:
+typedef struct {
+  int cbData;
+  unsigned char *pbData;
+} CRYPT_DATA_BLOB_1;
+typedef unsigned uint32_t;
+void fn1_1(void *p1, const void *p2) { p1 != p2; }
+
+void fn2_1(uint32_t *p1, unsigned char *p2, uint32_t p3) {
+  unsigned i = 0;
+  for (0; i < p3; i++)
+fn1_1(p1 + i, p2 + i * 0);// expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous}}
+}
+
+struct A_1 {
+  CRYPT_DATA_BLOB_1 value;
+  uint32_t m_fn1() {
+uint32_t a;
+if (value.pbData)
+  fn2_1(&a, value.pbData, value.cbData);
+return 0;
+  }
+};
+struct {
+  A_1 HashAlgId;
+} *b;
+void fn3() {
+  uint32_t c, d;
+  d = b->HashAlgId.m_fn1();
+  d << 0 | 0 | 0;
+  c = 0;
+  0 | 1 << 0 | 0 && b;
+}
+
+// case 3:
+struct ST {
+  char c;
+};
+char *p;
+int foo1(ST);
+int foo2() {
+  ST *p1 = (ST *)(p);  // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption}}
+  while (p1->c & 0x0F || p1->c & 0x07)
+p1 = p1 + foo1(*p1);
+}
+
+int foo3(int *node) {
+  int i = foo2();
+  if (i)
+return foo2();
+}
\ No newline at end of file
Index: include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===
--- inc

Re: [PATCH] D12163: [Patch] [Analyzer] BugReporter.cpp:2869: Assertion failed: !RemainingNodes.empty() && "No error node found in the trimmed graph" (PR 24184)

2015-08-20 Thread Ying Yi via cfe-commits
MaggieYi updated this revision to Diff 32671.
MaggieYi added a comment.

Hi Anna,

Many thanks for your comments. I have modified the patch to address your 
comments. Please let me know what you think.

PS: If the updated patch looks good to you, could you please commit it for me 
(as I do not have commit access) ?

Many thanks,
Ying Yi


http://reviews.llvm.org/D12163

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  test/Analysis/PR24184.cpp
  test/Analysis/malloc.c

Index: test/Analysis/malloc.c
===
--- test/Analysis/malloc.c
+++ test/Analysis/malloc.c
@@ -1386,7 +1386,8 @@
   int *s;
   char *b = realloc(a->p, size);
   char *m = realloc(a->p, size); // expected-warning {{Attempt to free released memory}}
-  return a->p;
+  //PR24184: Object "a->p" is returned after being freed by calling "realloc".
+  return a->p; // expected-warning {{Use of memory after it is freed}}
 }
 
 // We should not warn in this case since the caller will presumably free a->p in all cases.
Index: test/Analysis/PR24184.cpp
===
--- /dev/null
+++ test/Analysis/PR24184.cpp
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -w -analyze -analyzer-eagerly-assume -fcxx-exceptions -analyzer-checker=core -analyzer-checker=alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 64 -verify %s
+// RUN: %clang_cc1 -w -analyze -analyzer-checker=core -analyzer-checker=cplusplus -fcxx-exceptions -analyzer-checker alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 63 -verify %s
+
+// These tests used to hit an assertion in the bug report. Test case from http://llvm.org/PR24184.
+typedef struct {
+  int cbData;
+  unsigned pbData;
+} CRYPT_DATA_BLOB;
+
+typedef enum { DT_NONCE_FIXED } DATA_TYPE;
+int a;
+typedef int *vcreate_t(int *, DATA_TYPE, int, int);
+void fn1(unsigned, unsigned) {
+  char b = 0;
+  for (; 1; a++, &b + a * 0) // expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous}}
+;
+}
+
+vcreate_t fn2;
+struct A {
+  CRYPT_DATA_BLOB value;
+  int m_fn1() {
+int c;
+value.pbData == 0;
+fn1(0, 0);
+  }
+};
+struct B {
+  A IkeHashAlg;
+  A IkeGType;
+  A NoncePhase1_r;
+};
+class C {
+  int m_fn2(B *);
+  void m_fn3(B *, int, int, int);
+};
+int C::m_fn2(B *p1) {
+  int *d;
+  int e = p1->IkeHashAlg.m_fn1();
+  unsigned f = p1->IkeGType.m_fn1(), h;
+  int g;
+  d = fn2(0, DT_NONCE_FIXED, (char)0, p1->NoncePhase1_r.value.cbData);
+  h = 0 | 0;
+  m_fn3(p1, 0, 0, 0);
+}
+
+// case 2:
+typedef struct {
+  int cbData;
+  unsigned char *pbData;
+} CRYPT_DATA_BLOB_1;
+typedef unsigned uint32_t;
+void fn1_1(void *p1, const void *p2) { p1 != p2; }
+
+void fn2_1(uint32_t *p1, unsigned char *p2, uint32_t p3) {
+  unsigned i = 0;
+  for (0; i < p3; i++)
+fn1_1(p1 + i, p2 + i * 0);// expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous}}
+}
+
+struct A_1 {
+  CRYPT_DATA_BLOB_1 value;
+  uint32_t m_fn1() {
+uint32_t a;
+if (value.pbData)
+  fn2_1(&a, value.pbData, value.cbData);
+return 0;
+  }
+};
+struct {
+  A_1 HashAlgId;
+} *b;
+void fn3() {
+  uint32_t c, d;
+  d = b->HashAlgId.m_fn1();
+  d << 0 | 0 | 0;
+  c = 0;
+  0 | 1 << 0 | 0 && b;
+}
+
+// case 3:
+struct ST {
+  char c;
+};
+char *p;
+int foo1(ST);
+int foo2() {
+  ST *p1 = (ST *)(p);  // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption}}
+  while (p1->c & 0x0F || p1->c & 0x07)
+p1 = p1 + foo1(*p1);
+}
+
+int foo3(int *node) {
+  int i = foo2();
+  if (i)
+return foo2();
+}
\ No newline at end of file
Index: include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -287,7 +287,10 @@
  bool MarkAsSink,
  ExplodedNode *P = nullptr,
  const ProgramPointTag *Tag = nullptr) {
-if (!State || (State == Pred->getState() && !Tag && !MarkAsSink))
+// It may not be safe to use the "Pred" node with no tag because the "Pred"
+// node may be recycled in the reclamation function.
+if (!State || (State == Pred->getState() && !Tag && !MarkAsSink &&
+   Pred->getLocation().getTag()))
   return Pred;
 
 Changed = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12163: [Patch] [Analyzer] BugReporter.cpp:2869: Assertion failed: !RemainingNodes.empty() && "No error node found in the trimmed graph" (PR 24184)

2015-08-27 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

Ping


http://reviews.llvm.org/D12163



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


Re: [PATCH] D12163: [Patch] [Analyzer] BugReporter.cpp:2869: Assertion failed: !RemainingNodes.empty() && "No error node found in the trimmed graph" (PR 24184)

2015-08-27 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

Thanks for helping me review and submit the patch.


http://reviews.llvm.org/D12163



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


[PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-04 Thread Ying Yi via cfe-commits
MaggieYi created this revision.
MaggieYi added reviewers: filcab, probinson, jmagee, phillip.power.
MaggieYi added a subscriber: cfe-commits.

Dear All,

This patch adds “--dependent-lib= libclang_rt.profile-x86_64.a” to the compiler 
command line when enabling code coverage on the PS4 target.   A previous PS4 
patch (http://reviews.llvm.org/rL250293) added -l libclang_rt.profile-x86_64.a 
to the linker command line, however, this meant the user needed to add –l when 
running the linker directly.  This patch will improve the user workflow.

Please let me know if this is an acceptable patch.

Regards,

Ying Yi
SN Systems Ltd - Sony Computer Entertainment Group.

http://reviews.llvm.org/D15222

Files:
  lib/Driver/Tools.cpp
  test/Driver/ps4-runtime-flags.c

Index: test/Driver/ps4-runtime-flags.c
===
--- /dev/null
+++ test/Driver/ps4-runtime-flags.c
@@ -0,0 +1,31 @@
+// REQUIRES: x86-registered-target
+//
+// Test the profile runtime library to be linked for PS4 compiler.
+// Check PS4 runtime flag --dependent-lib which does not append the default library search path.
+//
+// RUN: %clang -target x86_64-scei-ps4 --coverage %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs -fprofile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fcoverage-mappinge %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+//
+// CHECK-PS4-PROFILE: "--dependent-lib=libclang_rt.profile-x86_64.a"
+// CHECK-PS4-NO-PROFILE-NOT: "--dependent-lib=libclang_rt.profile-x86_64.a"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3116,6 +3116,23 @@
   }
 }
 
+static void addPS4ProfileRTArgs(const ToolChain &TC, const ArgList &Args,
+ArgStringList &CmdArgs) {
+  if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
+false) ||
+   Args.hasFlag(options::OPT_fprofile_generate,
+   

Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-11 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

Ping


http://reviews.llvm.org/D15222



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


Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-14 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

Thanks for reviewing the patch. I try to answer your questions, could you 
please let me know if this makes sense to you?

Regards,



Comment at: lib/Driver/Tools.cpp:4064
@@ -4046,1 +4063,3 @@
 
+  // Add runtime flag for PS4 when PGO or Coverage are enabled.
+  if (getToolChain().getTriple().isPS4CPU())

vsk wrote:
> Profiling instrumentation seems orthogonal to PIC. Could you keep the calls 
> to `addPS4ProfileRTArgs` in their original locations?
Because this patch is adding “--dependent-lib= libclang_rt.profile-x86_64.a” to 
the compiler command line (CC1), instead of adding –l to the linker command. I 
had to move the function “addPS4ProfileRTArgs” call from “ConstructPS4LinkJob” 
to the “ConstructJob” function.


Comment at: test/Driver/ps4-runtime-flags.c:8
@@ +7,3 @@
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs -fprofile-arcs %s 
-### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | 
FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s

vsk wrote:
> This tests whether ArgList::hasFlag() works. It doesn't really stress your 
> patch. Please omit it.
I believe these do test my patch. My patch has changed the code from 
“Args.hasArg(options::…)” to “Args.hasFlag(options:: …)”.  This changes the 
behavior from simply requiring a switch (hasArg) to requiring the switches in 
the correct order (hasFlag).


Comment at: test/Driver/ps4-runtime-flags.c:10
@@ +9,3 @@
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | 
FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s 
-### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | 
FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s

vsk wrote:
> ^ Ditto.
See response to line 8.


Comment at: test/Driver/ps4-runtime-flags.c:11
@@ +10,3 @@
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s 
-### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | 
FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-PS4-PROFILE %s

vsk wrote:
> Looks identical to line 9. Unless I'm missing something, this should be 
> removed.
Thanks. I will remove this line and upload a new patch.


Comment at: test/Driver/ps4-runtime-flags.c:14
@@ +13,3 @@
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate 
-fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s

vsk wrote:
> Omit?
See response to line 8.


Comment at: test/Driver/ps4-runtime-flags.c:16
@@ +15,3 @@
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate 
-fno-profile-generate %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate 
-fno-profile-instr-generate %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-PS4-NO-PROFILE %s

vsk wrote:
> This one too.
See response to line 8.


Comment at: test/Driver/ps4-runtime-flags.c:22
@@ +21,3 @@
+// RUN: %clang -target x86_64-scei-ps4 
-fprofile-instr-generate=somefile.profraw %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate 
-fprofile-instr-generate %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate 
-fcoverage-mappinge %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s

vsk wrote:
> And this.
See response to line 8.


Comment at: test/Driver/ps4-runtime-flags.c:23
@@ +22,3 @@
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate 
-fprofile-instr-generate %s -### 2>&1 | FileCheck 
--check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate 
-fcoverage-mappinge %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate %s -### 
2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s

vsk w

Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-14 Thread Ying Yi via cfe-commits
MaggieYi updated this revision to Diff 42711.
MaggieYi added a comment.

Following Vedant's comments, two test issues have been fixed.


http://reviews.llvm.org/D15222

Files:
  lib/Driver/Tools.cpp
  test/Driver/ps4-runtime-flags.c

Index: test/Driver/ps4-runtime-flags.c
===
--- /dev/null
+++ test/Driver/ps4-runtime-flags.c
@@ -0,0 +1,30 @@
+// REQUIRES: x86-registered-target
+//
+// Test the profile runtime library to be linked for PS4 compiler.
+// Check PS4 runtime flag --dependent-lib which does not append the default library search path.
+//
+// RUN: %clang -target x86_64-scei-ps4 --coverage %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs -fprofile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fcoverage-mapping %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+//
+// CHECK-PS4-PROFILE: "--dependent-lib=libclang_rt.profile-x86_64.a"
+// CHECK-PS4-NO-PROFILE-NOT: "--dependent-lib=libclang_rt.profile-x86_64.a"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3112,6 +3112,23 @@
   }
 }
 
+static void addPS4ProfileRTArgs(const ToolChain &TC, const ArgList &Args,
+ArgStringList &CmdArgs) {
+  if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
+false) ||
+   Args.hasFlag(options::OPT_fprofile_generate,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasFlag(options::OPT_fprofile_generate_EQ,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasFlag(options::OPT_fprofile_instr_generate,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasFlag(options::OPT_fprofile_instr_generate_EQ,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasArg(options::OPT_fcreate_profile) ||
+   Args.hasArg(options::OPT_coverage)))
+CmdArgs.push_back("--dependent-lib=libclang_rt.profile-x86_64.a");
+}
+
 /// Parses the various -fpic/-

Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-15 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

My patch changes 6 compiler flags, which are –coverage, -fprofile-arcs, 
-fprofile-generate, -fprofile-generate=, -fprofile-instr-generate, 
-fprofile-instr-generate=. I would like to keep line 7-10 in order to verify 
the change to using “hasFlag” instead of “hasArg”. For the other switches, I 
could simplify the tests to only check “–fx” and “–fno-x” in order to cut down 
on test proliferation.

Do you think that would be acceptable?


http://reviews.llvm.org/D15222



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


Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-15 Thread Ying Yi via cfe-commits
MaggieYi updated this revision to Diff 42874.
MaggieYi added a comment.

Thanks, I have updated the test following your comments.


http://reviews.llvm.org/D15222

Files:
  lib/Driver/Tools.cpp
  test/Driver/ps4-runtime-flags.c

Index: test/Driver/ps4-runtime-flags.c
===
--- /dev/null
+++ test/Driver/ps4-runtime-flags.c
@@ -0,0 +1,19 @@
+// REQUIRES: x86-registered-target
+//
+// Test the profile runtime library to be linked for PS4 compiler.
+// Check PS4 runtime flag --dependent-lib which does not append the default library search path.
+//
+// RUN: %clang -target x86_64-scei-ps4 --coverage %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs -fprofile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-arcs %s -### 2>&1 | FileCheck -check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s
+// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s
+//
+// CHECK-PS4-PROFILE: "--dependent-lib=libclang_rt.profile-x86_64.a"
+// CHECK-PS4-NO-PROFILE-NOT: "--dependent-lib=libclang_rt.profile-x86_64.a"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3112,6 +3112,23 @@
   }
 }
 
+static void addPS4ProfileRTArgs(const ToolChain &TC, const ArgList &Args,
+ArgStringList &CmdArgs) {
+  if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
+false) ||
+   Args.hasFlag(options::OPT_fprofile_generate,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasFlag(options::OPT_fprofile_generate_EQ,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasFlag(options::OPT_fprofile_instr_generate,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasFlag(options::OPT_fprofile_instr_generate_EQ,
+options::OPT_fno_profile_instr_generate, false) ||
+   Args.hasArg(options::OPT_fcreate_profile) ||
+   Args.hasArg(options::OPT_coverage)))
+CmdArgs.push_back("--dependent-lib=libclang_rt.profile-x86_64.a");
+}
+
 /// Parses the various -fpic/-fPIC/-fpie/-fPIE arguments.  Then,
 /// smooshes them together with platform defaults, to decide whether
 /// this compile should be using PIC mode or not. Returns a tuple of
@@ -4047,6 +4064,10 @@
 
   addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
 
+  // Add runtime flag for PS4 when PGO or Coverage are enabled.
+  if (getToolChain().getTriple().isPS4CPU())
+addPS4ProfileRTArgs(getToolChain(), Args, CmdArgs);
+
   // Pass options for controlling the default header search paths.
   if (Args.hasArg(options::OPT_nostdinc)) {
 CmdArgs.push_back("-nostdsysteminc");
@@ -10067,21 +10088,6 @@
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 
-static void AddPS4ProfileRT(const ToolChain &TC, const ArgList &Args,
-ArgStringList &CmdArgs) {
-  if (!(Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
- false) ||
-Args.hasArg(options::OPT_fprofile_generate) ||
-Args.hasArg(options::OPT_fprofile_instr_generate) ||
-Args.hasArg(options::OPT_fcreate_profile) ||
-Args.hasArg(options::OPT_coverage)))
-return;
-
-  assert(TC.getTriple().isPS4CPU() &&
- "Profiling libraries are only implemented for the PS4 CPU");
-  CmdArgs.push_back("-lclang_rt.profile-x86_64");
-}
-
 static void AddPS4SanitizerArgs(const ToolChain &TC, ArgStringList &CmdArgs) {
   const SanitizerArgs &SanArgs = TC.getSanitizerArgs();
   if (SanArgs.needsUbsanRt()) {
@@ -10146,8 +10152,6 @@
 CmdArgs.push_back("-lpthread");
   }
 
-  AddPS4ProfileRT(ToolChain, Args, CmdArgs);
-
   const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("ps4-ld"));
 
   C.add

Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-16 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

Could someone commit it for me please (as I do not have commit access)? Thanks


http://reviews.llvm.org/D15222



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


Re: [PATCH] D15222: [Patch][Profile] add “--dependent-lib= libclang_rt.profile-x86_64.a” to the CC1 command line when enabling code coverage on PS4

2015-12-17 Thread Ying Yi via cfe-commits
MaggieYi added a comment.

Thanks Paul for your help.


Repository:
  rL LLVM

http://reviews.llvm.org/D15222



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