TITLE: Generalized Behrend version for Grothendieck-Lefschetz trace formula
QUESTION [6 upvotes]: [MOVED HERE FROM MSE.]
The statement of the Grothendieck-Lefschetz fixed point theorem is well-known. For a proper algebraic variety $X$ over $\mathbb F_q$,
$$\#X(\mathbb F_q) =\sum_i (−1)^i Tr(Fr_X, H^i_c(X, \mathbb Q_l)).$$
Also known is the version for general constructible l-adic sheaves $\mathcal F$:
$$\sum_{x\in X(\mathbb F_q)} Tr(Fr_x,\mathcal F_x)=\sum_i (−1)^i Tr(Fr_X, H^i_c(X, \mathcal F)).$$
Thirdly, K. Behrend proved an analog for the first formula in the context of algebraic stacks (replacing the scheme $X$ by a Noetherian algebraic stack $\mathcal X$).

Now my question is: is there a version of the second formula for an
  algebraic stack $\mathcal X$ (with nice hypotheses if necessary)?

It would seem natural, since the second formula is a generalization of the first, and the first is true in the context of algebraic stacks by Behrend's work. However, the second formula does not follow directly from the first in the case of schemes (as far as I know: I would be glad if it were true!), so I am not in the position to easily extend the proof of the second formula in the more general context of stacks.
Thank you in advance.
ADDED QUESTION: Moreover, why is the sum on the left of the second formula finite when the scheme (or stack) is not of finite type? Behrend speaks about this problem, but I do not find where he solves it, if he does.

REPLY [10 votes]: This is Theorem 4.2 of Shenghao Sun's paper $L$-Series of Artin stacks over finite fields, Algebra & Number Theory 6 (2012) pp 47–122, doi:10.2140/ant.2012.6.47, arXiv:1008.3689.

Let $f:\mathscr X_0\to\mathscr Y_0$ be a morphism of  $\mathbb F_q$-algebraic stacks, and let $K_0\in  W^{-,stra}_m(\mathscr X_0,\overline{\mathbb  Q}_{\ell})$ be a convergent complex of sheaves.
  Then 
(i) (Finiteness) $f_!K_0$ is a convergent complex of sheaves on
  $\mathscr Y_0,$ and 
(ii) (Trace formula) $c_v(\mathscr X_0,K_0)=c_v(\mathscr  Y_0,f_!K_0)$
  for every integer $v\ge1.$

Here $c_v$ is the sum of the trace of the $v$th power of Frobenius. Applying this in the case where $\mathscr Y_0$ is a point gets you what you want.